Skip to content

chore: align @implicitNotFound and @implicitAmbigous with the spec #22371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2025
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