Scala seems to apply the implicit class transform in the highest possible expression, as in the following example:
scala> class B { def b = { println("bb"); true } }
defined class B
scala> class A { def a = { println("aa"); new B } }
defined class A
scala> (new A).a.b
aa
bb
res16: Boolean = true
scala> class XXX(b: => Boolean) { def xxx = 42 }
defined class XXX
scala> implicit def toXXX(b: => Boolean) = new XXX(b)
toXXX: (b: => Boolean)XXX
scala> (new A).a.b.xxx
res18: Int = 42
I am very pleased with this fact, but my question is, what part of the SLS defines this behavior? Why does he, for example, not evaluate (new A).a.bto trueand simply apply the transformation to this value?
source
share