Closed hobwekiva closed 6 years ago
trait Foo[+A] implicit def foo[A <: Singleton](implicit v: ValueOf[A]): Foo[A] = new Foo[A] { } val s = "" implicitly[ValueOf[s.type]] // works implicitly[Foo[s.type]] // doesn't work
trait Foo[+A] implicit def foo[A <: Singleton]: Foo[A] = new Foo[A] { } val s = "" implicitly[Foo[s.type]] // works
If Foo is invariant, implicit resolution works. It is specific to ValueOf[A] as can be shown by:
ValueOf[A]
trait Foo[+A] trait Boo[A] implicit def boo[A <: Singleton]: Boo[A] = new Boo[A] { } implicit def foo[A <: Singleton](implicit v: Boo[A]): Foo[A] = new Foo[A] { } val s = "" implicitly[Foo[s.type]] // works fine
This turns out not to be an issue with ValueOf per se, but rather an artefact of type inference which is quite tricky to reproduce without ValueOf or something equivalent.
ValueOf
Fixed in https://github.com/milessabin/scala/commit/b5d676c3ec743d625d778565e6e3c5554a394b00.
If Foo is invariant, implicit resolution works. It is specific to
ValueOf[A]
as can be shown by: