Self typing:
class MyClass1
class MyClass2
trait MyTrait {
self: MyClass1 =>
val i = 1
}
scala> new MyClass1 with MyTrait
res0: MyClass1 with MyTrait = $anon$1@3f0762f6
scala> new MyClass2 with MyTrait
<console>:1: error: illegal inheritance;
self-type MyClass2 with MyTrait does not conform to MyTrait's selftype MyTrait with MyClass1
new MyClass2 with MyTrait
^
See also Self references part of scala
tag wiki.