diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index e870ffd0fc90..3a2f16438c88 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -1420,6 +1420,10 @@ trait Checking { case Literal(_) => // ok case _ => report.error(em"@${cls.name} needs a string literal as argument", arg.srcPos) + case Apply(tycon, arg :: Nil) if cls == defn.ImplicitNotFoundAnnot || cls == defn.ImplicitAmbiguousAnnot => + arg.tpe.widenTermRefExpr.normalized match + case _: ConstantType => () + case _ => report.error(em"@${cls.name} requires constant expressions as a parameter", arg.srcPos) case _ => tree diff --git a/tests/neg/i22367.check b/tests/neg/i22367.check new file mode 100644 index 000000000000..7a6333d0b8bb --- /dev/null +++ b/tests/neg/i22367.check @@ -0,0 +1,8 @@ +-- Error: tests/neg/i22367.scala:3:36 ---------------------------------------------------------------------------------- +3 |@annotation.implicitAmbiguous("cba".reverse) // error + | ^^^^^^^^^^^^^ + | @implicitAmbiguous requires constant expressions as a parameter +-- Error: tests/neg/i22367.scala:6:47 ---------------------------------------------------------------------------------- +6 |def f(using @annotation.implicitNotFound("cba".reverse) e: E[Int]): Unit = () // error + | ^^^^^^^^^^^^^ + | @implicitNotFound requires constant expressions as a parameter diff --git a/tests/neg/i22367.scala b/tests/neg/i22367.scala new file mode 100644 index 000000000000..076e13baaf55 --- /dev/null +++ b/tests/neg/i22367.scala @@ -0,0 +1,6 @@ +trait E[T] + +@annotation.implicitAmbiguous("cba".reverse) // error +given E[Int] = ??? + +def f(using @annotation.implicitNotFound("cba".reverse) e: E[Int]): Unit = () // error