I was trying to find any information (docs, specs, etc) on this but the topic seems to be pretty ungoogleable. I'm asking for any references on why the following works.
trait Foo[A]
package bar {
trait Bar
private[bar] object Bar {
implicit val b: Foo[Bar] = null
}
}
import bar._
def foo[A: Foo](a: A): Foo[A] = implicitly[Foo[A]]
foo(new Bar) // compiles
Somehow, the compiler was able to locate the implicit value of type Foo[Bar]
in the package-private companion object Bar
. Why?
To clarify my question. Everything changes is we change the companion object like shown below (implicit value is private but enclosing object is not). The code above won't compile with this Bar
.
package bar {
trait Bar
object Bar {
private implicit val b: Foo[Bar] = null
}
}
Is there some docs/specs that explain why this happens?