Meaning of super in stacked traits depends on call site?

Viewed 125

I can't come up with a very good description of this in words, so, please take a look at this example:

trait Base { def foo = "Base" }
trait One extends Base { override def foo = "One <: " + super.foo }
trait Two extends Base { override def foo = "Two <: " + super.foo }

new Base with One with Two {} foo

This prints: Two <: One <: Base, which is what I expect. Now, I am trying to add another level, so that overriding traits would not have to call super explicitly. Like this:

trait Base { def foo = "Base" }
trait Foo extends Base { def bar = foo + " <: " + super.foo }
trait One extends Foo { override def foo = "One" }
trait Two extends Foo { override def foo = "Two" }

new Foo with One with Two {} bar

Here, the last line prints out Two <: Base

So, it looks like in the first example super means One, while in the last one it skips One and goes directly to Base.

Why is this happening? Shouldn't behavior be the same?

2 Answers
Related