title: Scala trait `this.type` in type parameter
body: <p>Have a look at these two simple traits:</p>
  
  <pre><code>trait TreeNode1[S] {
      def subNodes: List[S]
  }
  trait TreeNode2 {
      def subNodes: List[this.type]
  }
  </code></pre>
  
  <p><em>(Not best naming, renamed them just to be brief.)</em><br>
  <code>TreeNode1</code> defines a tree node with its children access, pointing their type <code>S</code>.<br>
  <code>TreeNode2</code> defines the same, but its children have the same type as the class the current trait is mixed in (another words, tree node with uniform subnodes).  </p>
  
  <p>In theory <strong><code>TreeNode2</code> is a particular case of <code>TreeNode1</code></strong>:</p>
  
  <pre><code>trait TreeNode2 extends TreeNode1[this.type] {...}
  </code></pre>
  
  <p>But <strong>Scala will not compile <code>TreeNode2</code></strong> with such an extension, because <code>this.type</code> can not be used in such way, although there are no any inconsistencies with its working in runtime.  </p>
  
  <p>How can I get around this situation? Or Scala do not offer such poorly used mechanism?</p>
  
  <hr>
  
  <p><em>The reason I need this construction is the following:</em></p>
  
  <p>I have another trait that requires <code>TreeNode1</code> to be mixed in. I also have some class that mixes <code>TreeNode1</code> with quite another children type. But I also have several classes which have the same type as they are:</p>
  
  <pre><code>class SomeTreeNode extends TreeNode1[SomeTreeNode]
  </code></pre>
  
  <p>So it will look prettier if I use <code>TreeNode2</code> for it:</p>
  
  <pre><code>class SomeTreeNode extends TreeNode2
  </code></pre>
  
  <p>Implementing the same logic. But for using <code>TreeNode2</code> should be a case of <code>TreeNode1</code>, which it actually is, but Scala doesn't agree with me.</p>
  
  <p>P.S. At least it is wondering as theoretical question about Scala, not for a wide practical use.</p>