In the book Scala in Depth . There’s this example of implicit scoping as follows:
scala> object Foo {
| trait Bar
| implicit def newBar = new Bar {
| override def toString = "Implicit Bar"
| }
| }
defined module Foo
scala> implicitly[Foo.Bar]
res0: Foo.Bar = Implicit Bar
My question here is how did implicitly find the implementation of the trait Bar in the above given example? I think I am a little confused by how implicitly works
Apparently, for Foo.Bar, it works like Foo#Bar, i.e.,
if T is a type projection S#U, the parts of S as well as T itselfare in implicit scope (7.2 of the spec, but see usual resources on implicit scope, such as you’re already consulting). (Update: Here is such a resource. It doesn’t illustrate exactly this case, and whether a real example would look as artificial.)