For the code below as I understand it linearization of expression
new E with D with C with B
is E -> C -> B -> D. So then shouldnt the expression d.foo() in the code
below evaluate to ECBD instead of CBDE. What am I missing?
trait A {
def foo(): String = ""
}
trait B extends A {
abstract override def foo() = "B" + super.foo()
}
trait C extends B {
abstract override def foo() = "C" + super.foo()
}
trait D extends A {
abstract override def foo() = "D" + super.foo()
}
class E extends A{
override def foo() = "E"
}
var d = new E with D with C with B;
d.foo() //prints CBDE
I have noticed that if I have a class F like below
class F extends A with D with C with B{
override def foo() = "F" + super.foo()
}
and do
new F().foo
it prints "FCBD"
It seems a bit inconsistent to me because class F is mixed in the same way as the expression but has a different print order