title: scala.collection.immutable.Vector cannot be cast to <My Class>
body: <p>I am perplexed why I cannot yield a collection from the following line of Scala code:</p>
  
  <pre><code>val pairs = for( v &lt;- vc; o &lt;- oc) yield (v,o)
  </code></pre>
  
  <p>It's inside of this function, which is using immutable Vectors.</p>
  
  <pre><code> private def recMergeVirtualAndReal(mCell: RCell, vc: Vector[Cell], oc: Vector[Cell]): Vector[Cell] = {
          var temp_oc = oc
          val pairs = for( v &lt;- vc; o &lt;- oc) yield (v,o)
          val newVCells =
            for((left, right) &lt;- pairs if left contains right) yield {
              temp_oc = temp_oc.filterNot(o =&gt; o == left || o == right)
              captureVCells(left,right,mCell)
            }
          if(newVCells.nonEmpty) recMergeVirtualAndReal(mCell, recMergeVirtualCells(newVCells ++ vc), temp_oc)
          else vc
        }
  </code></pre>
  
  <p>I get the following error in the stack trace:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: scala.collection.immutable.Vector cannot be cast to game.Cell
      at model.Board$$anonfun$10.apply(Board.scala:223)
      at scala.collection.immutable.List.flatMap(List.scala:327)
  </code></pre>
  
  <p>I'm confused because I am not trying to cast anything, its just a simple statement without any type conversions.</p>
  
  <p>I also tried this in case the compiler couldn't understand the types:</p>
  
  <pre><code>val pairs = for( v: Cell &lt;- vc: Vector[Cell]; o: Cell &lt;- oc: Vector[Cell]) yield (v: Cell,o: Cell)
  </code></pre>