Closed
Description
Compiler version
Scala 3.7.0-RC1-bin-20250204-d75ca7f-NIGHTLY
Minimized code
I fixed a bug in (#22035) where arguments were lifted, breaking assumptions later in the compiler.
However I haven't special-cased it for explicit constructor calls, so we currently get:
class ann(x: Int = 3, y: Int = 4) extends annotation.Annotation
class C(x: Int = 3, y: Int = 4)
@main def main =
val a: Int @ann(y={println(1); 1}, x={println(2); 2}) = 42
val b = new ann(y={println(1); 1}, x={println(2); 2})
val c = new C(y={println(1); 1}, x={println(2); 2})
~/scala-snippets-6 scala -S 3.nightly -Xprint:typer --server=false annot-default-args.scala
Downloading Scala 3.7.0-RC1-bin-20250204-d75ca7f-NIGHTLY compiler
[[syntax trees at end of typer]] // /Users/mbovel/scala-snippets-6/annot-default-args.scala
...
@main def main: Unit =
{
val a:
Int @ann(
x =
{
println(2)
2
}
,
y =
{
println(1)
1
}
)
= 42
val b: ann =
new ann(
x =
{
println(2)
2
}
,
y =
{
println(1)
1
}
)
val c: C =
{
val y$1: Int =
{
println(1)
1
}
val x$1: Int =
{
println(2)
2
}
new C(x = x$1, y = y$1)
}
()
}
}
...
}
2
1
1
2
Arguably, the arguments should still be lifted when the instance is constructed explicitly, as in b
above.