Implicit value / conversion in package-private companion object
I tried to find any information (docs, specs, etc.) on this subject, but the topic seems to be pretty invulnerable. I am asking for any links as to 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 find the implicit value of the type Foo[Bar]
in the package private-companion object Bar
. Why?
To clarify my question. Everything changes - we change the companion object as shown below (the implicit value is private, but the enclosing object is not). The above code will not compile with this Bar
.
package bar {
trait Bar
object Bar {
private implicit val b: Foo[Bar] = null
}
}
Are there any docs / specs out there explaining why this is happening?
source to share
No one has answered this question yet
See similar questions:
or similar: