Skip to content

Commit c9d670f

Browse files
committed
Fix CollectSuper
Add comment what it is supposed to achieve and change the implementation to follow the comment.
1 parent 7062b90 commit c9d670f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.ast.Trees._
55
import dotty.tools.dotc.core.Contexts.Context
66
import dotty.tools.dotc.core.Symbols._
7+
import dotty.tools.dotc.core.Flags.Trait
78
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
89

9-
/** Collect all super calls except to the parent class.
10+
/** Collect all super calls to trait members.
11+
*
12+
* For each super reference to trait member, register a call from the current class to the
13+
* owner of the referenced member.
1014
*
1115
* This information is used to know if it is safe to remove a redundant mixin class.
1216
* A redundant mixin class is one that is implemented by another mixin class. As the
@@ -20,12 +24,9 @@ class CollectSuperCalls extends MiniPhaseTransform {
2024

2125
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = {
2226
tree.qualifier match {
23-
case Super(qual, mix) if mix.nonEmpty =>
24-
val classSymbol: ClassSymbol = qual match {
25-
case qual: This => qual.symbol.asClass.classSymbol
26-
case qual => qual.symbol.info.classSymbol.asClass
27-
}
28-
registerSuperCall(classSymbol, tree.symbol.owner.asClass)
27+
case sup: Super =>
28+
if (tree.symbol.owner.is(Trait))
29+
registerSuperCall(ctx.owner.enclosingClass.asClass, tree.symbol.owner.asClass)
2930
case _ =>
3031
}
3132
tree

0 commit comments

Comments
 (0)