Description
Compiler version
Welcome to Scala 3.1.1 (17, Java Java HotSpot(TM) 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
Minimized code and output
I executed the following lines in the Scala REPL:
trait A {
def m(a:Int): Int
}
trait B extends A {
override def m(a:Int): Int = { return a; }
}
trait C extends A {
abstract override def m(a:Int):Int = { return super.m(a); }
}
trait D extends B with C {
override def m(a:Int):Int = { return super.m(a); }
}
trait E extends C with B {
abstract override def m(a:Int):Int = { return super.m(a); }
}
class X extends E with D
and with entering the last line I see the following stack trace (and the shell exits).
Click to expand!
Exception in thread "main" java.lang.AssertionError: assertion failed: cannot rebind method repl$$rs$line$3$C$$super$m, repl$$rs$line$3$C$$super$m m
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.transform.ResolveSuper$.rebindSuper(ResolveSuper.scala:115)
at dotty.tools.dotc.transform.ResolveSuper.superAccessors$2$$anonfun$2(ResolveSuper.scala:52)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.transform.ResolveSuper.superAccessors$3(ResolveSuper.scala:53)
at dotty.tools.dotc.transform.ResolveSuper.$anonfun$1(ResolveSuper.scala:55)
at scala.collection.immutable.List.flatMap(List.scala:293)
at dotty.tools.dotc.transform.ResolveSuper.transformTemplate(ResolveSuper.scala:55)
at dotty.tools.dotc.transform.ResolveSuper.transformTemplate(ResolveSuper.scala:43)
at dotty.tools.dotc.transform.MegaPhase.goTemplate(MegaPhase.scala:1004)
at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:363)
at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:429)
at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:256)
at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:437)
at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:442)
at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:442)
at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:442)
at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:362)
at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:429)
at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:256)
at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:437)
at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:442)
at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:442)
at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:442)
at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:382)
at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:385)
at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:429)
at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:448)
at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:460)
at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:308)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:309)
at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:261)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
at dotty.tools.dotc.Run.runPhases$5(Run.scala:272)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
at dotty.tools.dotc.Run.compileUnits(Run.scala:289)
at dotty.tools.dotc.Run.compileUnits(Run.scala:228)
at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:155)
at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:165)
at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:250)
at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:218)
at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:152)
at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:155)
at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:174)
at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:155)
at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:117)
at dotty.tools.repl.Main$.main(Main.scala:6)
at dotty.tools.repl.Main.main(Main.scala)
Expectation
Well, the definition of class X
is not correct and therefore I expected an error message. The linearization of X
is X D E B C A
i.e. class C
is not mixed in correctly as method C.m
is declared abstract
(i.e. needs to be mixed in in such a way that a concrete implementation follows class C
in the linearization). The problem seems to be the definition of method D.m
which should have been declared as abstract override
.
Scala 2 reports an error on definition of method D.m
:
`abstract override` modifiers required to override:
absoverride def m(a: Int): Int (defined in trait C)
with override def m(a: Int): Int (defined in trait D)
If method D.m
were declared as abstract override
, then the Scala compiler would report the following error on creation of class X
without crashing:
scala> class X extends E with D
-- Error: ----------------------------------------------------------------------
1 |class X extends E with D
| ^
|class X needs to be abstract, since def m(a: Int): Int in trait A is not defined
|(The class implements abstract override def m(a: Int): Int in trait D but that definition still needs an implementation)
1 error found