Reputation: 1363
I have found there rules for implicict resolution i SLS:
if T is a compound type T1 with ... with Tn, the union of the parts of T1, ..., Tn, as well as T itself
if T is a parameterized type S[T1, ..., Tn], the union of the parts of S and T1, ..., Tn
if T is a singleton type p.type, the parts of the type of p
if T is a type projection S#U, the parts of S as well as T itself
in all other cases, just T itself
Is example below implicit resolution based on rule 4?
object Foo{
trait Bar
implicit def newBar = new Bar{
override def toString = "Implicit Bar"
}
}
implicitly[Foo.Bar]
Thanks
Zlaja
Upvotes: 1
Views: 385
Reputation: 67280
Yes, I believe that is correct. I think for a singleton object Foo
, type Foo.Bar
is the same as Foo.type#Bar
:
implicitly[Foo.type#Bar] // ok
Also:
def a(f: Foo.type#Bar) {}
def b(f: Foo.Bar) { a(f) } // accepted
def c(f: Foo.Bar) {}
def d(f: Foo.type#Bar) { c(f) } // accepted
Upvotes: 1