-
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
Support variance annotations in -Ykind-projector
mode
#12341
Support variance annotations in -Ykind-projector
mode
#12341
Conversation
private def makeKindProjectorTypeDef(name: TypeName): TypeDef = | ||
TypeDef(name, WildcardTypeBoundsTree()).withFlags(Param) | ||
private def makeKindProjectorTypeDef(name: TypeName): TypeDef = { | ||
val isVarianceAnnotated = name.lastPart.startsWith("+") || name.lastPart.startsWith("-") |
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.
Couldn't name.startsWith
be used given that these are user-written names and so should only have one part?
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.
@smarter Changed to name.startsWith
TypeDef(name, WildcardTypeBoundsTree()).withFlags(Param) | ||
private def makeKindProjectorTypeDef(name: TypeName): TypeDef = { | ||
val isVarianceAnnotated = name.lastPart.startsWith("+") || name.lastPart.startsWith("-") | ||
val unannotatedName = if (isVarianceAnnotated) name.mapLast(_.drop(1)) else name |
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.
Would be nice to add a comment mentioning that we can strip the variance because it's inferred.
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.
@smarter Added a comment explaining the decision to just strip the variance
fe8ebd7
to
536661d
Compare
This change expands the supported subset of `kind-projector` syntax, specifically: * `+*` and `-*` variance annotated variants of `*` placeholder * Variance annotated named parameters in `λ` - `λ[(`-R`, `+E`, `+A`) => F[R, E, A]]`
536661d
to
653c5fd
Compare
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.
LGTM, thanks!
This change expands the supported subset of
kind-projector
syntax, specifically:+*
and-*
variance annotated versions of the*
placeholderλ
syntax -λ[(`-R`, `+E`, `+A`) => F[R, E, A]]
This change ignores the variance flag specified using
kind-projector
's syntax – since variance annotations in type lambdas are deprecated in Scala 3, the real variance of a variable will be inferred separately. I believe that may be acceptable since-Ykind-projector
's raison d'être is to allow cross-compilation with existing Scala 2 code, not for writing new code, that is the variance annotations may be assumed to have been checked by the Scala 2 compiler.Related PRs and issues: #7139 #7775
Prompted by discussion in scala/scala#9605