The following code snippet does not type check with scala 2.12.4 but it does type check with dotty
object O {
type A = AnyRef { def M: AnyRef { def a : Int }}
type B = AnyRef { def M: AnyRef { def b : Int }}
class U[-X]
def f(a: U[A], b: U[B]) = Seq(a, b)
}
The error message is
found : O.U[O.B]
(which expands to) O.U[AnyRef{def M: AnyRef{def b: Int}}]
required: O.U[O.B with O.A]
(which expands to) O.U[AnyRef{def M: AnyRef{def b: Int}} with AnyRef{def M: AnyRef{def a: Int}}]
def f(a: U[A], b: U[B]) = Seq(a, b)
^
Expanding type aliases does not help
def g(
a: U[AnyRef { def M: AnyRef { def a: Int }}],
b: U[AnyRef { def M: AnyRef { def b: Int }}]) = Seq(a, b)
Now it complains
error: type mismatch;
found : O.U[AnyRef{def M: AnyRef{def a: Int}}]
required: O.U[AnyRef{def M: AnyRef}]
b: U[AnyRef { def M: AnyRef { def b: Int }}]) = Seq(a, b)
^
error: type mismatch;
found : O.U[AnyRef{def M: AnyRef{def b: Int}}]
required: O.U[AnyRef{def M: AnyRef}]
b: U[AnyRef { def M: AnyRef { def b: Int }}]) = Seq(a, b)
The code type-checks with a type annotation
type C = AnyRef { def M: AnyRef { def a: Int; def b : Int }}
def h(a: U[A], b: U[B]) = Seq[U[C]](a, b)
The following code snippet does not type check with scala 2.12.4 but it does type check with dotty
The error message is
Expanding type aliases does not help
Now it complains
The code type-checks with a type annotation