@@ -1073,6 +1073,19 @@ trait Checking {
1073
1073
if ! Inliner .inInlineMethod && ! ctx.isInlineContext then
1074
1074
report.error(em " $what can only be used in an inline method " , pos)
1075
1075
1076
+ /** Check arguments of compiler-defined annotations */
1077
+ def checkAnnotArgs (tree : Tree )(using Context ): tree.type =
1078
+ val cls = Annotations .annotClass(tree)
1079
+ def needsStringLit (arg : Tree ) =
1080
+ report.error(em " @ ${cls.name} needs a string literal as argument " , arg.srcPos)
1081
+ tree match
1082
+ case Apply (tycon, arg :: Nil ) if cls == defn.TargetNameAnnot =>
1083
+ arg match
1084
+ case Literal (_) => // ok
1085
+ case _ => needsStringLit(arg)
1086
+ case _ =>
1087
+ tree
1088
+
1076
1089
/** 1. Check that all case classes that extend `scala.reflect.Enum` are `enum` cases
1077
1090
* 2. Check that parameterised `enum` cases do not extend java.lang.Enum.
1078
1091
* 3. Check that only a static `enum` base class can extend java.lang.Enum.
@@ -1235,6 +1248,7 @@ trait NoChecking extends ReChecking {
1235
1248
override def checkImplicitConversionDefOK (sym : Symbol )(using Context ): Unit = ()
1236
1249
override def checkImplicitConversionUseOK (tree : Tree )(using Context ): Unit = ()
1237
1250
override def checkFeasibleParent (tp : Type , pos : SrcPos , where : => String = " " )(using Context ): Type = tp
1251
+ override def checkAnnotArgs (tree : Tree )(using Context ): tree.type = tree
1238
1252
override def checkInlineConformant (tpt : Tree , tree : Tree , sym : Symbol )(using Context ): Unit = ()
1239
1253
override def checkNoTargetNameConflict (stats : List [Tree ])(using Context ): Unit = ()
1240
1254
override def checkParentCall (call : Tree , caller : ClassSymbol )(using Context ): Unit = ()
0 commit comments