@@ -19,7 +19,7 @@ import core.Scopes.newScopeWith
19
19
import core .Decorators .*
20
20
import core .Constants .*
21
21
import core .Definitions .*
22
- import core .Annotations .BodyAnnotation
22
+ import core .Annotations .{ Annotation , BodyAnnotation }
23
23
import typer .NoChecking
24
24
import inlines .Inlines
25
25
import typer .ProtoTypes .*
@@ -550,6 +550,11 @@ object Erasure {
550
550
* - Java statics and packages can only be used in selections.
551
551
*/
552
552
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
553
558
if ! ctx.mode.is(Mode .Type ) then
554
559
if isErased(tree) then
555
560
val msg =
@@ -562,15 +567,15 @@ object Erasure {
562
567
report.error(msg, tree.srcPos)
563
568
tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot ) match
564
569
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 ) =>
567
572
val addendum = tree match
568
573
case tree : RefTree
569
574
if tree.symbol == defn.Compiletime_deferred && tree.name != nme.deferred =>
570
575
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. "
571
576
case _ =>
572
577
" "
573
- (c.stringValue + + addendum).toMessage
578
+ (msg + addendum).toMessage
574
579
case _ =>
575
580
em """ Reference to ${tree.symbol.showLocated} should not have survived,
576
581
|it should have been processed and eliminated during expansion of an enclosing macro or term erasure. """
0 commit comments