Confusing Scala type mismatch error with 'uncheckedVariance' in signature

Viewed 887

First the error:

/Users/rob/Workspace/Boiled.scala:9: error: type mismatch;
 found   : DataSetup{type Mem <: Product with Serializable{val ids: List[Int]; def copy(ids: List[Int]): this.Mem; def copy$default$1: List[Int]}; object Mem; type Memory = this.Mem}
 required: DataSetup{type Mem <: Product with Serializable{val ids: List[Int]; def copy(ids: List[Int]): this.Mem; def copy$default$1: List[Int] @scala.annotation.unchecked.uncheckedVariance}; object Mem; type Memory = this.Mem}
 val dataSetup = new DataSetup {
     ^

Lovely isn't it? It points to a line where I try to create an instance of the DataSetup trait. It is of course a boiled-down version of the real code.

trait DataSetup {
  type Memory <: AnyRef with Serializable 
  def run(): Memory
}

object Use {

  val dataSetup = new DataSetup {     // <---- error reported here
    case class Mem(ids: List[Int])
    type Memory = Mem
    def run(): Memory = {
      val ids = List(1,2,3)
      Mem(ids)
    }
  }

}

I really have no idea what it's complaining about. Anyone?

1 Answers
Related