Should the linearization order be changed to put the derived class first?

No replies

Wed, 2011-10-26, 21:02

ellbur

Joined: 2011-10-26,

Hello,

The way I understand things right now, if I have a hierarchy:

trait A
trait B
class C extends B with A

The linearization order is C->A->B. This makes intuitive sense, but I
often find myself wanting to write code like

trait A {
def things: List[Int]
}

trait B {
abstract override def things = 7 :: super.things
}

val a = new B {
def x = List(1, 2, 3)
}

where a.x is now List(7, 1, 2, 3)

In fact, maybe I'm doing things wrong, but I actually want to do this
even more than I want to use regular mixins. As far as I can tell, the
only reason this is not possible is because the derived class comes
first in the linearization order. So what I do is manually change the
linearization order: