Implicits compiler bug?
First, a short description. It seems that if I put an implicit for some
other type in a companion object and import that implicit into scope of
the class it isn't found during implicit resolution until it is referenced
explicitly once(or defined above the class). Example below.
class A(val a: Something)
object A {
implicit val default: A = ... //found by default
}
object B {
def func(fn: => T)(implicit a: A) = ...
}
class Broken {
def doSomething = {
import Broken._ // or Broken.actual
B.func { ... } // Uses A.default, not Broken.actual for implicit
}
}
object Broken {
implicit val actual: A = ...
}
class Fixed {
def doSomething = {
import Fixed._
println(actual) //reference actual
B.func { ... } // uses Fixed.actual
}
}
object Fixed {
implicit val actual: A = ...
}
object WTF {
implicit val actual: A = ...
}
class WTF {
def doSomething = {
import WTF._
B.func { ... } // With object definition first this works without
referencing actual
}
}
I am kind of assuming at this point I've found a compiler bug, so I'll
open a jira against Scala, but in the mean time I'm wondering if anyone
here knows if this is expected, or if there's already an open bug for
this?
No comments:
Post a Comment