Closed
Description
Compiler version
Scala 3.4.2-RC1-bin-20240229-9fe0111-NIGHTLY-git-9fe0111 (17.0.8, Java OpenJDK 64-Bit Server VM)
Minimized code
Let dependentAnnotation.scala
contain:
package dependentAnnotation
class lambdaAnnot(g: () => Int) extends annotation.StaticAnnotation
def f(x: Int): Int @lambdaAnnot(() => x + 1) = x
@main def main =
val y: Int = 5
val z = f(y)
Output
scala-cli compile -S 3.nightly -Xprint:typer --server=false dependentAnnotation.scala
outputs
...
val z:
Int @lambdaAnnot(
{
def $anonfun(): Int = x.+(1) // Not substituted 😱
closure($anonfun)
}
)
= dependentAnnotation.f(y)
()
}
...
Expectation
x
should be substituted to y
.
This is the case if the annotation takes an Int
parameter instead of () => Int
.
Example without a lambda
package dependentAnnotation2
class intAnnot(predicate: Int) extends annotation.StaticAnnotation
def f(x: Int): Int @intAnnot(x + 1) = x
@main def main =
val y: Int = 5
val z = f(y)
scala-cli compile -S 3.nightly -Xprint:typer --server=false dependentAnnotation2.scala
...
val z: Int @intAnnot(y.+(1)) = dependentAnnotation2.f(y)
...