import scala.annotation.implicitNotFound
@implicitNotFound("Not found for ${A}")
type F[A]
@implicitNotFound("Not found for ${A}")
trait G[A]
def f[T] given F[T] = ???
def g[T] given G[T] = ???
@main def Main = {
f[String]
g[String]
}
Out:
-- Error: ../pg/Main.scala:13:11 -----------------------------------------------
13 | f[String]
| ^
| Not found for ${A}
-- Error: ../pg/Main.scala:14:11 -----------------------------------------------
14 | g[String]
| ^
| Not found for String
two errors found
Activity
[-]@implicitNotFound string interpolator doesn't work for types[/-][+]@implicitNotFound string interpolator doesn't work with types[/+]anatoliykmetyuk commentedon Aug 23, 2019
We should also support this:
Maybe substitute placeholders if the type lambda is partially applied:
b-studios commentedon May 14, 2021
In the meantime the observed behavior changed. The first error is not
"Not found for ${A}", butNot found forwhich is even more confusing.For completeness: it also does not work on opaque types which came as a surprise to me:
prolativ commentedon Jun 11, 2021
@b-studios am I right that
@implicitNotFound(or annotations in general) should not be allowed on non-opaque types? because they're just aliases?b-studios commentedon Jun 17, 2021
Actually, I am not sure about this. It sounds like it would be easier to forbid them, but if I search for a type before dealising and it has an annotation, then in general it should be possible to report it for this case. I wouldn't use the annotation for the right-hand side, though.
prolativ commentedon Jun 17, 2021
Well, currently when you have
then for
summon[Baz]you get the custom message but forsummon[Bar]you don't. That's quite unintuitive for me. Should these two cases be equivalent or not? Or what's wrong with right-hand side annotations then?julienrf commentedon Jun 17, 2021
I think it makes sense to support at least abstract type members (which have not been aliased yet).
YulawOne commentedon Jul 2, 2021
No sure about difficulty here, but I just got an example where it's really useful to have
implicitNotFoundon type alias:While without it compilation message is quite cryptic about missing given. So I don't think annotation should be forbidden 🤔
joroKr21 commentedon Dec 28, 2023
Hmm, in Scala 3.3.1 it doesn't work at all for type aliases with a type parameter. It does work for simple type aliases.
Fix implicitNotFound message for type aliases
13 remaining items