为什么使用绑定到类值参数的类型成员会产生“类型不匹配”错误?例如:
scala> class A { type t }
defined class A
scala> class B(val a: A)
defined class B
scala> val aInt = new A { type t = Int }
aInt: A{type t = Int} = $anon$1@6ccc7368
scala> val b = new B(aInt)
b: B = B@834518
scala> val i: b.a.t = 1
<console>:11: error: type mismatch;
found : Int(1)
required: b.a.t
val i: b.a.t = 1
^
奇怪的是,当我使用未定义为类参数的值时,一切正常:
scala> abstract class C { val a: A }
defined class C
scala> val c = new C { val a = aInt }
c: C{val a: A{type t = Int}} = $anon$1@1e815aad
scala> val i: c.a.t = 1
i: c.a.t = 1
这种行为的原因是什么?