You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importscala.annotation.implicitNotFound@implicitNotFound("Not found for ${A}")
typeF[A]
@implicitNotFound("Not found for ${A}")
traitG[A]
deff[T] givenF[T] =???defg[T] givenG[T] =???@main defMain= {
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 forString
two errors found
changed the title [-]@implicitNotFound string interpolator doesn't work for types[/-][+]@implicitNotFound string interpolator doesn't work with types[/+]on Aug 23, 2019
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.
import scala.annotation.implicitNotFound
trait Foo
type Bar = Foo @implicitNotFound("There's no Bar")
@implicitNotFound("There's no Baz") type Baz = Foo
then for summon[Baz] you get the custom message but for summon[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?
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 for
which 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
implicitNotFound
on 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