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
compiler silently ignores ambiguous implicits, pretends none exist (unless in -Xlog-implicits) #7697
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7697?orig=1 |
@retronym said: qscalac -Xlog-implicits sandbox/test1.scala
sandbox/test1.scala:9: <string2int: error> is not a valid implicit value for String("abc") => Int because:
reference to string2int is ambiguous;
it is imported twice in the same scope by
import o2._
and import o1._
val x: Int = "abc"
^
sandbox/test1.scala:9: error: type mismatch;
found : String("abc")
required: Int
val x: Int = "abc"
^
one error found
Given separate compilation, we can only base our decision on the type signature, not on the body of the method. We should figure out how to emit the useful output of |
@paulp said: |
@retronym said: |
@paulp said: |
@paulp said: https://gist.github.com/paulp/36b67d27400a9f3be96a class Bippy(override val toString: String)
trait A { implicit def lowPriority: Bippy = new Bippy("A") }
object B extends A { implicit def highPriority: Bippy = new Bippy("B") }
object C { implicit def highPriority: Bippy = new Bippy("C") }
object Test {
def main(args: Array[String]): Unit = {
import B._, C._
println( implicitly[Bippy] ) // Prints: A
}
} |
@retronym said:
But one man's trash is another man's treasure when it comes to these diagnostics. I don't think they are in a state to turn on by default. |
@paulp said: |
The appended error message is seen under -Ylog:typer, but under normal compilation scalac offers nothing.
Secondarily, it would be nice if this situation were recognized as the non-conflict which it is: the "conflicting" implicits are prefix-insensitive and the identical method implementation. This situation arises very easily when mixing implicits into package objects and trying to evolve codebases.
But at the very least how about we give people a hint what happened.
The text was updated successfully, but these errors were encountered: