typelevel / scala

Typelevel Scala, a fork of Scala
http://typelevel.org/scala/
372 stars 21 forks source link

ValueOf interferes with implicit resolution of covariant typeclasses of singleton types #172

Closed hobwekiva closed 6 years ago

hobwekiva commented 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:

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
milessabin commented 6 years ago

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.

milessabin commented 6 years ago

Fixed in https://github.com/milessabin/scala/commit/b5d676c3ec743d625d778565e6e3c5554a394b00.