Skip to content

Commit

Permalink
chore: align @implicitNotFound and @implicitAmbigous with the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal authored and bracevac committed Jan 19, 2025
1 parent e3eedbc commit aef4979
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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
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

0 comments on commit aef4979

Please sign in to comment.