1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
object p { class Foo[T] { // Crashes: def f(): Foo[T] = (if (true) this else this).bar // Works: // def f(): Foo[T] = new Bar(if (true) this else this).bar } implicit class Bar[A](val self: A) { def bar(): A = self } }