title: type parameter with underlying type in - Scala
body: <p>Lets say I've a trait with a type <code>A</code> that is a subclass of <code>Any</code> and a method called <code>nextState</code> that has that same type as a parameter.</p>
  
  <pre><code>trait GameEnvironment {
    type A &lt;: Any
    def nextState(state: A, input: Int): (A, Boolean)
  }
  </code></pre>
  
  <p>This trait is then extended by a class called <code>Tetris</code> that overrides the type member <code>A</code> and the method <code>nextState</code>.</p>
  
  <pre><code>class Tetris extends GameEnvironment {
    override type A = ((Array[Array[Int]]), Int)
  
    def nextState(state: (Array[Array[Int]], Int), input: Int): 
    ((Array[Array[Int]], Int), Boolean) = {
  
  
       ((state, false))
    }
  }
  </code></pre>
  
  <p>Now in another class called <code>ReinLib</code> I create a <code>GameEnvironment</code>, and I also have a function that takes in a parameter <code>GameEnvironment#A</code>.</p>
  
  <pre><code>class ReinLib(val mode: String) {
    val env : GameEnvironment = new Tetris()
  
    def simulateStep(state: GameEnvironment#A, input: Int): (Boolean) = 
      {
         env.nextState(state, input)._2
      }
  }
  </code></pre>
  
  <p>Now if I compile this code I get an error </p>
  
  <blockquote>
    <p>type mismatch state.type (with underlying type...</p>
  </blockquote>
  
  <p>From what I gather this happens since the compiler is not certain which type <code>state</code> has. However I could not seem to find how to solve my issue, so I'm wondering how one would get around this.</p>