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
Lift artificial restrictions on ConstantAnnotation
s
#9379
Merged
Merged
Conversation
This file contains 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
lrytz
commented
Dec 9, 2020
lrytz
force-pushed
the
constAnn
branch
2 times, most recently
from
December 11, 2020 20:22
56d2c42
to
0110f9a
Compare
lrytz
changed the title
typecheck ConstantAnnotation normally
Typecheck ConstantAnnotations normally, not like Java annotations
Dec 11, 2020
dwijnand
reviewed
Dec 17, 2020
dwijnand
reviewed
Dec 17, 2020
dwijnand
approved these changes
Dec 17, 2020
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.
Shame this has to undo what typer did to named/default args, making it net more LOC in the compiler. But I guess the effect is progress.
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.
It's not big, but it allows for more things, so I feel we should bullet point this for users, in the release notes. |
SethTisue
changed the title
Typecheck ConstantAnnotations normally, not like Java annotations
Lift artificial restrictions on Feb 19, 2021
ConstantAnnotation
s
This was referenced Mar 12, 2021
Closed
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 ConstantAnnotation
This accomplished by typechecking
ConstantAnnotation
s 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
New
and the individualargs
were 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)