-
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
Lift arguments of explicitly constructed annotations #22553
base: main
Are you sure you want to change the base?
Conversation
8cc0706
to
a9557b6
Compare
a9557b6
to
5f8ae12
Compare
@@ -13,3 +13,6 @@ def test = | |||
@annot(44) val z3 = 45 | |||
@annot2(y = Array("Hello", y)) val z4 = 45 | |||
|
|||
// Arguments are still lifted if the annotation class is instantiated | |||
// explicitly. See #22526. | |||
val z5 = new annot2(y = Array("World"), x = 1) |
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.
What happens on @annot(y = new A, x = new annot(y = new B, x = new C))
?
I think in principle, the AST should be
new annot(
x = { val y$1 = new B; val x$1 = new C; new annot(x = x$1, y = y$1) }
y = new 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.
I have just pushed a commit that addresses that.
I can agree with the principle in this case. But in general, it should be noted that trees in annotation arguments are currently not guaranteed to be valid by any definition. We should spec it.
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 good to me.
The Scala 3 typer seems to use modes a bit different than Scala 2.
Scala 2 clears mode bits in several places, e.g. in typedArg
. Mode flags can be declared to stay active when passing those thresholds. I didn't spot anything like that in Scala 3.
Scala 3 also seems to use expected types (FunProto, PolyProto) for things that are done with modes in Scala 2 (FUNmode, POLYmode).
I'm just saying I'm not familiar with modes in Scala 3, so maybe someone else should also review this.
if wideFormal eq formal then ctx.retractMode(Mode.InAnnotation) | ||
else ctx.retractMode(Mode.InAnnotation).withNotNullInfos(ctx.notNullInfos.retractMutables) |
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.
Can this flag be added to argCtx in
def argCtx(app: untpd.Tree)(using Context): Context = |
Fixes #22526.