Confuse Scala type mismatch error with 'uncheckedVariance' in signature

First 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, right? It points to the line where I am trying to instantiate the attribute DataSetup. This, of course, is its own version of 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 don't know what he is complaining about. Is anyone

+4
source share
1 answer

Sometimes error messages improved in the last value of 2.11.

<console>:14: error: type mismatch;
 found   : DataSetup{type Mem(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>) <: Product with Serializable{val ids: List[Int]; def copy(ids: List[Int]): this.Mem(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>); def copy$default$1: List[Int]}; type Memory = this.Mem(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)}
 required: DataSetup{type Mem(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>) <: Product with Serializable{val ids: List[Int]; def copy(ids: List[Int]): this.Mem(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>); def copy$default$1: List[Int] @scala.annotation.unchecked.uncheckedVariance}; object Mem; type Memory = this.Mem(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)(in <refinement of DataSetup>)}
         val dataSetup = new DataSetup {     // <---- error reported here
             ^

In any case, it seems that the annotation (added synthetically to the arg method by default copy) is lost in the output type.

val dataSetup: DataSetup = new DataSetup {     // <---- no error here

Obviously, the type does not match without annotation. It is worth asking why:

https://issues.scala-lang.org/browse/SI-8071

:

- , , AnyRef.

+2

All Articles