When porting my project from Scala 2.10 to 2.11 I got a sudden compilation error with type parametrization. I tried to modify and pinpoint; still something strange went wrong. Could someone explain? BTW I was happy with this regression (or progression), since it motivated me to simplify the code.
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
}
}
I have a hasty partial answer:
When you change the bound on
T
inNodeCode
, you lose the information that the previous bound was a refinement withN
tied tothis.type
.The last bound wins.
This is the question I was thinking of.
This may not suit your needs:
Edit: that doesn't seem to help, sorry. Something else is going on.