this.type required in a path dependent context:
scala> class A { class B; def f(b: B): A = this }
defined class A
scala> val a1 = new A; val b1 = new a1.B; val a2 = new A
a1: A = A@721f1edb
b1: a1.B = A$B@5922f665
a2: A = A@65e8e9b
scala> a1.f(b1)
res6: A = A@721f1edb
scala> a2.f(b1)
<console>:12: error: type mismatch;
found : a1.B
required: a2.B
a2.f(b1)
^
, , . , new a1.B a1.B, B. :
scala> a1.f(b1).f(b1)
<console>:11: error: type mismatch;
found : a1.B
required: _2.B where val _2: A
a1.f(b1).f(b1)
^
, f A, . this.type , :
scala> class A { class B; def f(b: B): this.type = this }
defined class A
scala> val a1 = new A; val b1 = new a1.B; val a2 = new A
a1: A = A@60c40d9c
b1: a1.B = A$B@6759ae65
a2: A = A@30c89de5
scala> a1.f(b1).f(b1)
res10: a1.type = A@60c40d9c