Skip to content

Commit 1270d13

Browse files
authored
chore: align @implicitNotFound and @implicitAmbigous with the spec (#22371)
Closes #22367 Closes #22346
2 parents 6a1714b + b73888d commit 1270d13

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

+4
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,10 @@ trait Checking {
14201420
case Literal(_) => // ok
14211421
case _ =>
14221422
report.error(em"@${cls.name} needs a string literal as argument", arg.srcPos)
1423+
case Apply(tycon, arg :: Nil) if cls == defn.ImplicitNotFoundAnnot || cls == defn.ImplicitAmbiguousAnnot =>
1424+
arg.tpe.widenTermRefExpr.normalized match
1425+
case _: ConstantType => ()
1426+
case _ => report.error(em"@${cls.name} requires constant expressions as a parameter", arg.srcPos)
14231427
case _ =>
14241428
tree
14251429

tests/neg/i22367.check

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg/i22367.scala:3:36 ----------------------------------------------------------------------------------
2+
3 |@annotation.implicitAmbiguous("cba".reverse) // error
3+
| ^^^^^^^^^^^^^
4+
| @implicitAmbiguous requires constant expressions as a parameter
5+
-- Error: tests/neg/i22367.scala:6:47 ----------------------------------------------------------------------------------
6+
6 |def f(using @annotation.implicitNotFound("cba".reverse) e: E[Int]): Unit = () // error
7+
| ^^^^^^^^^^^^^
8+
| @implicitNotFound requires constant expressions as a parameter

tests/neg/i22367.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait E[T]
2+
3+
@annotation.implicitAmbiguous("cba".reverse) // error
4+
given E[Int] = ???
5+
6+
def f(using @annotation.implicitNotFound("cba".reverse) e: E[Int]): Unit = () // error

0 commit comments

Comments
 (0)