禁止混合特定的特征

Knu*_*daa 7 type-systems scala

鉴于:

trait Foo
trait Bar { this: Foo => }
trait NoBar { this: Foo => }
Run Code Online (Sandbox Code Playgroud)

有没有办法可以欺骗类型系统禁止:

new Foo with Bar with NoBar {}
Run Code Online (Sandbox Code Playgroud)

Kim*_*bel 12

并且类型擦除再次节省了一天:

trait Foo
trait Dummy[A]
trait Bar extends Dummy[Bar]{ this: Foo => }
trait NoBar extends Dummy[NoBar]{ this: Foo => }
new Foo with Bar with NoBar {}
Run Code Online (Sandbox Code Playgroud)

这会导致以下错误:

illegal inheritance; anonymous class $anon inherits different
type instances of trait Dummy: Dummy[Bar] and Dummy[NoBar]
Run Code Online (Sandbox Code Playgroud)