Skip to content

Type-annotated inline expression inside implicitNotFound annotation disables it completely #22346

Closed
@belamenso

Description

@belamenso

Compiler version

3.6.2

Minimized code

inline val msg: String = "abc"
trait E[T]
def f(using @annotation.implicitNotFound(msg) e: E[Int]): Unit = ()
@main def hello(): Unit = f

Output

[error] -- [E172] Type Error: Main.scala:5:27 
[error] 5 |@main def hello(): Unit = f
[error]   |                           ^
[error]   |    No given instance of type E[Int] was found for parameter e of method f

Expectation

The error No given instance of type E[Int] was found for parameter e of method f is the default one that was supposed to be customized to abc. The reason this happens is the : String type annotation.

If you just do inline val msg = "abc" then it will work as expected:

[error] -- [E172] Type Error: Main.scala:5:27 
[error] 5 |@main def hello(): Unit = f
[error]   |                           ^
[error]   |                           abc
  • inline val msg = "abc" works
  • inline val msg = "ab" + "c" works
  • inline val msg: String = "abc" does not work (!)
  • inline val msg = "cba".reverse does not work

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions