New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix variance handling for parameterized type aliases #8651
Conversation
The variance of a type alias was taken to be the variance of its right-hand side, but that doesn't make sense for a parameterized type alias which is free to appear in any position: variance checking should only kick in when it is applied to something. It was possible to work around this by using a type lambda instead of a type alias, cats just had to do that: typelevel/cats#3264
e6b5ee7
to
b7d9d19
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
override def variance = | ||
// A non-applied parameterized type alias can appear in any variance position | ||
if (typeParams.nonEmpty) | ||
Invariant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks sound to me :-)
else if (isLocalToThis) | ||
Bivariant | ||
else | ||
info.typeSymbol.variance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can no longer construct the soundness argument for this; but, then again, I also don't have a counter-example. (And it's been like this forever 🤷♂ )
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
green community build run: https://scala-ci.typesafe.com/job/scala-2.13.x-integrate-community-build/3148/ |
Yay |
The variance of a type alias was taken to be the variance of its
right-hand side, but that doesn't make sense for a parameterized type
alias which is free to appear in any position: variance checking should
only kick in when it is applied to something.
It was possible to work around this by using a type lambda instead of a
type alias, cats just had to do that: typelevel/cats#3264