Skip to content

Commit de050de

Browse files
committed
Support non-literal annot params with constant types
1 parent cbf9e3d commit de050de

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
240240
private def emitArgument(av: AnnotationVisitor,
241241
name: String,
242242
arg: Tree, bcodeStore: BCodeHelpers)(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
243-
normalizeArgument(arg) match {
243+
val narg = normalizeArgument(arg)
244+
// Transformation phases are not run on annotation trees, so we need to run
245+
// `constToLiteral` at this point.
246+
val t = constToLiteral(narg)(ctx.withPhase(ctx.erasurePhase))
247+
t match {
244248
case Literal(const @ Constant(_)) =>
245249
const.tag match {
246250
case BooleanTag | ByteTag | ShortTag | CharTag | IntTag | LongTag | FloatTag | DoubleTag => av.visit(name, const.value)

tests/pos/java-annot/J.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java.lang.annotation.*;
2+
3+
@Retention(RetentionPolicy.RUNTIME)
4+
public @interface J {
5+
String value();
6+
}

tests/pos/java-annot/S.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object C {
2+
val cs: "cs" = "cs"
3+
}
4+
5+
object S {
6+
@J(C.cs) // OK: cs is a constant
7+
def f(): Int = 1
8+
}

0 commit comments

Comments
 (0)