Skip to content
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

Do not lift annotation arguments (bis) #22046

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@ trait Applications extends Compatibility {
case (arg: NamedArg, _) => arg
case (arg, name) => NamedArg(name, arg)
}
else if isAnnotConstr(methRef.symbol) then
typedArgs
else if !sameSeq(args, orderedArgs) && !typedArgs.forall(isSafeArg) then
// need to lift arguments to maintain evaluation order in the
// presence of argument reorderings.
Expand Down
23 changes: 23 additions & 0 deletions tests/printing/dependent-annot-default-args.check
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,39 @@ package <empty> {
final module class annot() extends AnyRef() { this: annot.type =>
def $lessinit$greater$default$2: Any @uncheckedVariance = 42
}
class annot2(x: Any, y: Array[Any]) extends annotation.Annotation() {
private[this] val x: Any
private[this] val y: Array[Any]
}
final lazy module val annot2: annot2 = new annot2()
final module class annot2() extends AnyRef() { this: annot2.type =>
def $lessinit$greater$default$1: Any @uncheckedVariance = -1
def $lessinit$greater$default$2: Array[Any] @uncheckedVariance =
Array.apply[Any](["Hello" : Any]*)(scala.reflect.ClassTag.Any)
}
final lazy module val dependent-annot-default-args$package:
dependent-annot-default-args$package =
new dependent-annot-default-args$package()
final module class dependent-annot-default-args$package() extends Object() {
this: dependent-annot-default-args$package.type =>
def f(x: Int): Int @annot(x) = x
def f2(x: Int):
Int @annot2(
y = Array.apply[Any](["Hello",x : Any]*)(scala.reflect.ClassTag.Any))
= x
def test: Unit =
{
val y: Int = ???
val z: Int @annot(y) = f(y)
val z2:
Int @annot2(
y = Array.apply[Any](["Hello",y : Any]*)(scala.reflect.ClassTag.Any)
)
= f2(y)
@annot(44) val z3: Int = 45
@annot2(
y = Array.apply[Any](["Hello",y : Any]*)(scala.reflect.ClassTag.Any))
val z4: Int = 45
()
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/printing/dependent-annot-default-args.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
class annot(x: Any, y: Any = 42) extends annotation.Annotation
class annot2(x: Any = -1, y: Array[Any] = Array("Hello")) extends annotation.Annotation

def f(x: Int): Int @annot(x) = x
def f2(x: Int): Int @annot2(y = Array("Hello", x)) = x

def test =
val y: Int = ???

val z = f(y)
val z2 = f2(y)

@annot(44) val z3 = 45
@annot2(y = Array("Hello", y)) val z4 = 45

Loading