Skip to content

Commit 3e6cdef

Browse files
authored
Merge pull request #1425 from dotty-staging/fix-#1423
Fix #1423: Fix owners of called methods in CollectSuperCalls.
2 parents bd71f78 + a9976bd commit 3e6cdef

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/dotty/tools/backend/jvm/CollectSuperCalls.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tools.backend.jvm
22

3-
import dotty.tools.dotc.ast.tpd._
4-
import dotty.tools.dotc.ast.Trees
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.ast.Trees._
55
import dotty.tools.dotc.core.Contexts.Context
66
import dotty.tools.dotc.core.Symbols._
77
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
@@ -14,17 +14,18 @@ import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, Transforme
1414
* the redundant mixin class could be required as a parent by the JVM.
1515
*/
1616
class CollectSuperCalls extends MiniPhaseTransform {
17+
import tpd._
1718

1819
def phaseName: String = "collectSuperCalls"
1920

20-
override def transformSuper(tree: Super)(implicit ctx: Context, info: TransformerInfo): Tree = {
21-
tree match {
22-
case Trees.Super(qual: This, mix) if mix.nonEmpty =>
21+
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = {
22+
tree.qualifier match {
23+
case Super(qual: This, mix) if mix.nonEmpty =>
2324
val classSymbol = qual.symbol.asClass.classSymbol
24-
registerSuperCall(classSymbol, tree.tpe.baseClasses.head)
25+
registerSuperCall(classSymbol, tree.symbol.owner.asClass)
2526
case _ =>
2627
}
27-
super.transformSuper(tree)
28+
tree
2829
}
2930

3031
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(implicit ctx: Context) = {

tests/run/i1423.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
2
3+
3
4+
1
5+
0

tests/run/i1423.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class B { def m: Int = 0 }
2+
class C extends B { override def m = 4 }
3+
trait T1 extends B { override def m = 1 }
4+
trait T2 extends T1 { override def m = 2 }
5+
trait T3 extends T1 { override def m = 3 }
6+
7+
trait T4 extends T1
8+
class D extends B {
9+
def f() = println(super[B].m)
10+
}
11+
12+
object Test extends C with T2 with T3 with T4 {
13+
def main(args: Array[String]): Unit = {
14+
println(m)
15+
println(super[T2].m)
16+
println(super[T3].m)
17+
println(super[T4].m)
18+
new D().f()
19+
}
20+
}

0 commit comments

Comments
 (0)