Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check was borrowed from:

for (case ConstantType(c) <- argument(i) map (_.tpe.widenTermRefExpr.normalized)) yield c

case _: ConstantType => ()
case _ => report.error(em"@${cls.name} requires constant expressions as a parameter", arg.srcPos)
case _ =>
tree

Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i22367.check
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/neg/i22367.scala
Original file line number Diff line number Diff line change
@@ -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
Loading