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?

+3
scala


source to share


No one has answered this question yet

See similar questions:

339
Where does Scala look for implicits?
2
Allowing an Implicit Typeclass for "Show"

or similar:

4
Scala - Make implicit value classes available in another scope
4
Finding Implicit Values ​​in Companion Nested Type Object
3
Why do val and def implement abstract methods at different times?
2
Implicit conversions on a common characteristic
2
Why does implicit object have higher precedence than implicit val in Scala companion objects?
2
Implicit value not found from companion object
0
How to mock a class object that is a private package
0
Why can't the Scala compiler use implicit inherited type conversion?
0
Scala: companions from subclasses
0
How do I do an implicit conversion in Scala?



All Articles
Loading...
X
Show
Funny
Dev
Pics