Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disallow mix of specific traits

Given:

trait Foo
trait Bar { this: Foo => }
trait NoBar { this: Foo => }

Is there a way a can trick the type system into disallowing:

new Foo with Bar with NoBar {}
like image 474
Knut Arne Vedaa Avatar asked Dec 23 '12 11:12

Knut Arne Vedaa


1 Answers

And type erasure saves the day again:

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 {}

This results in the following error:

illegal inheritance; anonymous class $anon inherits different
type instances of trait Dummy: Dummy[Bar] and Dummy[NoBar]
like image 74
Kim Stebel Avatar answered Oct 15 '22 22:10

Kim Stebel