Why doesn't this produce ambiguous implicit error?
I expected this code to fail with "error: ambiguous implicit values",
however it does in fact compile and run:
object AmbiguousImplicitsShouldntCompile extends App {
class A {def x = 1}
class B extends A { override def x = 2}
def f(implicit i: A) = i.x
implicit val a = new A
implicit val b = new B
println(f) // prints 2
}
Is this a bug in scala? Or is this correct behavior? I tried reading the
Scala Language Specification for anything relevant, but the parts on
implicit parameter resolution and overloading resolution are quite dense.
No comments:
Post a Comment