@@ -19,7 +19,7 @@ import core.Scopes.newScopeWith
1919import core .Decorators .*
2020import core .Constants .*
2121import core .Definitions .*
22- import core .Annotations .BodyAnnotation
22+ import core .Annotations .{ Annotation , BodyAnnotation }
2323import typer .NoChecking
2424import inlines .Inlines
2525import typer .ProtoTypes .*
@@ -550,6 +550,11 @@ object Erasure {
550550 * - Java statics and packages can only be used in selections.
551551 */
552552 private def checkNotErased (tree : Tree )(using Context ): tree.type =
553+ extension (annot : Annotation ) def argumentAdaptedConstantString (i : Int )(using Context ): Option [String ] =
554+ annot.argument(i) match
555+ case Some (Literal (Constant (s : String ))) => Some (s)
556+ case Some (TypeApply (Select (Literal (Constant (s : String )), nme.asInstanceOf_), _)) => Some (s)
557+ case _ => None
553558 if ! ctx.mode.is(Mode .Type ) then
554559 if isErased(tree) then
555560 val msg =
@@ -562,15 +567,15 @@ object Erasure {
562567 report.error(msg, tree.srcPos)
563568 tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot ) match
564569 case Some (annot) =>
565- val message = annot.argumentConstant( 0 ) match
566- case Some (c ) =>
570+ val message = annot.argumentConstantString( 0 ).orElse(annot.argumentAdaptedConstantString( 0 ) ) match
571+ case Some (msg ) =>
567572 val addendum = tree match
568573 case tree : RefTree
569574 if tree.symbol == defn.Compiletime_deferred && tree.name != nme.deferred =>
570575 i " . \n Note that `deferred` can only be used under its own name when implementing a given in a trait; ` ${tree.name}` is not accepted. "
571576 case _ =>
572577 " "
573- (c.stringValue + + addendum).toMessage
578+ (msg + addendum).toMessage
574579 case _ =>
575580 em """ Reference to ${tree.symbol.showLocated} should not have survived,
576581 |it should have been processed and eliminated during expansion of an enclosing macro or term erasure. """
0 commit comments