Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/dotty/tools/backend/jvm/CollectSuperCalls.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dotty.tools.backend.jvm

import dotty.tools.dotc.ast.tpd._
import dotty.tools.dotc.ast.Trees
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
Expand All @@ -14,17 +14,18 @@ import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, Transforme
* the redundant mixin class could be required as a parent by the JVM.
*/
class CollectSuperCalls extends MiniPhaseTransform {
import tpd._

def phaseName: String = "collectSuperCalls"

override def transformSuper(tree: Super)(implicit ctx: Context, info: TransformerInfo): Tree = {
tree match {
case Trees.Super(qual: This, mix) if mix.nonEmpty =>
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = {
tree.qualifier match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fruitless outer pattern match (and this matters at least a little bit, because Select is a common node). More efficient:

tree.qualifier match { ... }

case Super(qual: This, mix) if mix.nonEmpty =>
val classSymbol = qual.symbol.asClass.classSymbol
registerSuperCall(classSymbol, tree.tpe.baseClasses.head)
registerSuperCall(classSymbol, tree.symbol.owner.asClass)
case _ =>
}
super.transformSuper(tree)
tree
}

private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(implicit ctx: Context) = {
Expand Down
5 changes: 5 additions & 0 deletions tests/run/i1423.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
2
3
1
0
20 changes: 20 additions & 0 deletions tests/run/i1423.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class B { def m: Int = 0 }
class C extends B { override def m = 4 }
trait T1 extends B { override def m = 1 }
trait T2 extends T1 { override def m = 2 }
trait T3 extends T1 { override def m = 3 }

trait T4 extends T1
class D extends B {
def f() = println(super[B].m)
}

object Test extends C with T2 with T3 with T4 {
def main(args: Array[String]): Unit = {
println(m)
println(super[T2].m)
println(super[T3].m)
println(super[T4].m)
new D().f()
}
}