この質問は、抽象型をオーバーライドするCakeパターンの質問に続き、UpperTypeBoundsでは機能しません。トレイトの抽象型を。でオーバーライドしたい<:
。前のリンクは、トレイトSで記述して線形化の順序を変更することで構成されるソリューションを提供します。ただし、次のコードでthis: Cake with S
名前を付けたコントロールの抽象化を追加しました。control
その中のメソッドを呼び出したいt
。
trait A {
def ping = println("ping")
}
trait Cake {
type T
}
trait S { this: Cake with S =>
type T <: A with S
def t: T
def s = println("test")
// def control(c: =>T): T = c // compile
// def control(c: =>T): T = c.s // does not compile
def control(c: =>T): T = c.t // does not compile
t.ping
t.s
}
しかし、このコードは私が説明できないコンパイルエラーを引き起こします
found : S.this.T#T
required: S.this.T
def control(c: =>T): T = c.t
^
なにが問題ですか ?