Following code does not compile with Scala 2 (tested 2.13.7 and Scala 2.12.15):
trait AttributeBase
trait Attribute extends AttributeBase {
def name: String
}
trait Base {
def attribute: AttributeBase
}
trait Derived { self: Base =>
def attribute: Attribute
def name = attribute.name
}
The code compiles fine with Scala 3. With Scala 2 the error is:
value name is not a member of AttributeBase
It compiles fine when extends
is used instead of a self type:
trait Derived extends Base {
Another possible workaround is:
def name = (this:Derived).attribute.name
Why is the type of Derived.attributed
assumed to be AttributeBase
and not Attribute
? Is this a Scala compiler bug, or some Scala 2 limitation?