-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implicit resolution differs from Scala 2 in presence of GADTs #5469
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
Comments
What are the chances of getting dotty to select |
@milessabin I checked and the following code also emits ambiguous warning (in scalac): @ object O {
sealed trait Box[T] { def value: T }
final case class IntBox(value: Int) extends Box[Int]
implicit def s1[T](implicit box: Box[T]): String = "generic: " + box.value
implicit def s2(implicit box: Box[Int]): String = "specific: " + box.value
implicit val box: Box[Int] = new IntBox(0)
val str = implicitly[String]
}
cmd3.sc:9: ambiguous implicit values:
both method s2 in object O of type (implicit box: ammonite.$sess.cmd3.O.Box[Int])String
and method s1 in object O of type [T](implicit box: ammonite.$sess.cmd3.O.Box[T])String
match expected type String
val str = implicitly[String]
^
Compilation Failed which would mean that selecting |
Right, but surely that's because scalac isn't able to identify |
I'm not familiar enough with implicit resolution to answer that. Frankly, I'm surprised that |
Ahh ... I misread your example. The reason scalac sees these as ambiguous is its odd (non-)handling of implicit arguments when computing the specificity of implicit methods ... see scala/bug#10526. I think this is a bug and I'd like to see it fixed: scala/scala#6139. |
dotty compiles following code:
The implicit resolved in
test
iss1
(the generic one).scalac
refuses to compile the code, saying that the implicit is ambiguous.The text was updated successfully, but these errors were encountered: