-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add reflect TypeLambda.paramVariances
#17568
Conversation
@neko-kai could you check if the test example is representative of your use cases? |
@nicolasstucki variances[[A] =>> K1Cov[A]] I think that's the case that broke in 3.3.0 - before that |
@nicolasstucki variances[[A, F[+_]] =>> F[A]] |
// from the test case
variances[[A, F[+B]] =>> F[A]] currently the result for |
TypeLambda.declaredVariances
TypeLambda.paramVariances
tests/run-macros/i16734/Test_2.scala
Outdated
println(variances[KFunky]) | ||
println(variances[[A, F[B]] =>> F[A]]) | ||
println(variances[[A, F[+B]] =>> F[A]]) | ||
println(variances[[A, F[-B]] =>> F[A]]) |
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.
@neko-kai to make these work, I used paramVariance
instead of declaredVariances
. Is this the functionality you need? See the variances in the check file. If it is what you need then you could also access this method reflectively as a workaround in 3.3.0
.
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.
@nicolasstucki
Yes, thank you! That's what I'll do right now, but it'd be great to have a public API anyway, to stop using reflection for this in the future.
I changed that when I switched to |
tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala
Outdated
Show resolved
Hide resolved
@@ -2212,6 +2212,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | |||
extension (self: TypeLambda) | |||
def param(idx: Int): TypeRepr = self.newParamRef(idx) | |||
def paramBounds: List[TypeBounds] = self.paramInfos | |||
def paramVariances: List[Flags] = |
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.
Having this just on TypeLambda
is a bit limiting since classes also have parameter with variance annotations, it would be nice if the same API worked for TypeLambda, TypeRef of classes and TypeRef of parameterized type aliases.
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 added Symbol.paramVariance
and added tests for all these cases. I did not add it on TypeRef
because it is more consistent if we go to the definition of the class and ask for the variances on it.
/** Variance flags for of this type parameter. | ||
* | ||
* Variance flags can be one of `Flags.{Covariant, Contravariant, EmptyFlags}`. | ||
* If this is not the symbol of a type parameter the result is `Flags.EmptyFlags`. |
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.
Could we simply assert that this is a type parameter to prevent misinterpreting EmptyFlags as Invariant on things which aren't type parameters?
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.
We do not show the distinction between type and term flags in the reflection API.
a14b547
to
c0880ad
Compare
needs a rebase |
c0880ad
to
f86a682
Compare
Fixes #16734