1

I have found there rules for implicict resolution i SLS:

  1. if T is a compound type T1 with ... with Tn, the union of the parts of T1, ..., Tn, as well as T itself

  2. if T is a parameterized type S[T1, ..., Tn], the union of the parts of S and T1, ..., Tn

  3. if T is a singleton type p.type, the parts of the type of p

  4. if T is a type projection S#U, the parts of S as well as T itself

  5. 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

0__
  • 66,707
  • 21
  • 171
  • 266
zlaja
  • 1,351
  • 3
  • 13
  • 23
  • Duplicate of http://stackoverflow.com/questions/13773964/how-does-implicitly-work-in-this-example-from-scala-in-depth which probably means there are other duplicates. – som-snytt Apr 16 '13 at 09:00

1 Answers1

1

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
0__
  • 66,707
  • 21
  • 171
  • 266