title: How to use Scala's this typing, abstract types, etc. to implement a Self type?
body: <p>I couldn't find the answer to this in any other question. Suppose that I have an abstract superclass Abstract0 with two subclasses, Concrete1 and Concrete1. I want to be able to define in Abstract0 something like</p>
  
  <pre><code>def setOption(...): Self = {...}
  </code></pre>
  
  <p>where Self would be the concrete subtype. This would allow chaining calls to setOption like this:</p>
  
  <pre><code>val obj = new Concrete1.setOption(...).setOption(...)
  </code></pre>
  
  <p>and still get Concrete1 as the inferred type of obj.</p>
  
  <p>What I don't want is to define this:</p>
  
  <pre><code>abstract class Abstract0[T &lt;: Abstract0[T]]
  </code></pre>
  
  <p>because it makes it harder for clients to handle this type. I tried various possibilities including an abstract type:</p>
  
  <pre><code>abstract class Abstract0 {
    type Self &lt;: Abstract0
  }
  
  class Concrete1 extends Abstract0 {
    type Self = Concrete1
  }
  </code></pre>
  
  <p>but then it is impossible to implement setOption, because <code>this</code> in Abstract0 does not have type Self. And using <code>this: Self =&gt;</code> also doesn't work in Abstract0.</p>
  
  <p>What solutions are there to this issue?</p>