title: Scala - same but different type
body: <p>I have the following code:</p>
  
  <pre><code>trait CellT[VAL &lt;: AnyVal] {
    var value: VAL
    type NEXT &lt;: AnyVal
    var next: CellT[NEXT]
  }
  
  abstract class Cell[VAL &lt;: AnyVal] extends CellT[VAL] {
    var next = this  // defaults to `this`. ERROR
  }
  
  // impl example:
  class CellInt extends Cell[Int] {
    var value: Int = 0
  }
  </code></pre>
  
  <p>The error says that</p>
  
  <blockquote>
    <p>overriding variable next in trait CellT of type
    Cell[Cell.this.NEXT]; variable next has
    incompatible type</p>
  </blockquote>
  
  <p>Here it is obvious that <code>this</code> will have the type <code>VAL &lt;: AnyVal</code> which is the same as <code>NEXT &lt;: AnyVal</code>, however, I still get the error. How can I tell Scala that <code>next</code> should be able to return anything of type <code>Cell[A &lt;: AnyVal]</code>, but this type should <em>not</em> be necessary the same as the class type parameter <code>[VAL &lt;: AnyVal]</code>??? Otherwise I could just use <code>[VAL]</code> but it will be too restrictive, for example for <code>Cell[Int]</code> it will restrict the <code>next</code> method to return only <code>Cell[Int]</code> type instances. But I want the <code>next</code> to be reassignable to any other <code>Cell[*]</code> types instances.</p>