在将我的项目从 Scala 2.10移植到 2.11 时,我遇到了类型参数化的突然编译错误。我试图修改和精确定位;还是有什么奇怪的地方出错了。有人可以解释一下吗?顺便说一句,我对这种回归(或进展)很满意,因为它促使我简化代码。
trait TNode {type N <: Node {type T = this.type}}
trait Node {type T <: TNode {type N = this.type}; def t: T}
trait TNodeCode[R] extends TNode {type N <: NodeCode[R]; val code: ()=>N=>R}
trait NodeCode[R] extends Node {type T <: TNodeCode[R]}
object Test {
def executeCode[R](n: Node, code: =>()=>R): R = {null.asInstanceOf[R]}
def executeTCode[N <: NodeCode[R], R](n: N): R = {
executeCode(n, ()=>n.t.code.apply.apply(n))
// compile error: ^
// type mismatch; found: n.type (with underlying type N) required: _1.N where val _1: n.T
}
}