Skip to content

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

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

Closed
belamenso opened this issue Jan 11, 2025 · 2 comments · Fixed by #22371
Closed

Comments

@belamenso
Copy link

belamenso commented Jan 11, 2025

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
@belamenso belamenso added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 11, 2025
@hamzaremmal
Copy link
Member

hamzaremmal commented Jan 12, 2025

inline val msg = "cba".reverse does not work

I'm not surprised about this one, and I'm not sure if it should work. If not, it should at least be an error. (It should be it's own issue, can you open it please ?)

inline val msg: String = "abc" does not work (!)

The current code tries to infer the value for it's type. See:

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

So to fix this issue, we should change how values are inlined in this case. Not sure how hard it would be to do.

@Gedochao Gedochao added area:annotations area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2025
@belamenso belamenso changed the title Certain inline expressions inside implicitNotFound annotation disable it completely Type-annotated inline expression inside implicitNotFound annotation disables it completely Jan 14, 2025
@belamenso
Copy link
Author

Ok, I have changed this one to be about : String, and moved the discussion about more complex things over to #22367 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants