Lift artificial restrictions on ConstantAnnotations#9379
Merged
lrytz merged 3 commits intoscala:2.13.xfrom Dec 17, 2020
Merged
Conversation
lrytz
commented
Dec 9, 2020
56d2c42 to
0110f9a
Compare
dwijnand
reviewed
Dec 17, 2020
dwijnand
reviewed
Dec 17, 2020
dwijnand
approved these changes
Dec 17, 2020
So far we handled ConstantAnnotations the same as Java annotations. Instead of typechecking the full parse tree `Apply(New(annot), args)`, the `New` and the individual `args` were typed individually. This is needed for Java annotations as there's no corresponding constructor. But for ConstantAnnotations we can just type check them normally and then extract the constants.
When extracting constants from an already typed ConstantAnnotation, don't call the typer again.
Java supports nested annotations as constant annotation arguments, but Scala's ConstantAnnotation doesn't. Better error message for this case.
Member
|
It's not big, but it allows for more things, so I feel we should bullet point this for users, in the release notes. |
ConstantAnnotations
This was referenced Mar 12, 2021
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR drops some artificial restrictions for annotations extending
ConstantAnnotation@constAnn(arg1, arg2)is now allowed without using named arguments@constAnn(arg)is now allowed for a generic annotationclass constAnn[T](x: T) extends ConstantAnnotationThis accomplished by typechecking
ConstantAnnotations normally, not like Java annotations.So far we handled ConstantAnnotations the same as Java annotations.
Instead of typechecking the full parse tree
Apply(New(annot), args),the
Newand the individualargswere typed individually. This isneeded for Java annotations as there's no corresponding constructor.
But for ConstantAnnotations we can just type check them normally and
then extract the constants.
Fixes scala/bug#11724.
Context: #9336 (comment)