Skip to content

Commit 69141c6

Browse files
committed
Fix trait constructors
Trait constructors added a this to the constructor of a trait, which is useless because the constructor's type is unit. By contrast, it's good to rename the DefDef to the new name.
1 parent 97635db commit 69141c6

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/dotty/tools/dotc/transform/TraitConstructors.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ import dotty.tools.dotc.core._
1111
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
1212

1313
/***
14-
* Renames constructors in traits so that backend will call them with invokeInterface
15-
* Also makes sure that renamed constructor bodies conforms to type of method
14+
* Renames constructors in traits so that backend will call them with invokeInterface
1615
*/
1716
class TraitConstructors extends MiniPhaseTransform with SymTransformer {
1817
import dotty.tools.dotc.ast.tpd._
1918
def phaseName: String = "traitConstructors"
2019

21-
override def treeTransformPhase: Phase = this.phase
22-
2320
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = {
2421
if (sym.isPrimaryConstructor && (sym.owner is Flags.Trait))
2522
sym.copySymDenotation(name = nme.IMPLCLASS_CONSTRUCTOR)
@@ -29,8 +26,7 @@ class TraitConstructors extends MiniPhaseTransform with SymTransformer {
2926
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
3027
val sym = tree.symbol
3128
if (sym.isPrimaryConstructor && (sym.owner is Flags.Trait))
32-
cpy.DefDef(tree)(rhs = Block(List(tree.rhs), This(tree.symbol.enclosingClass.asClass)))
29+
cpy.DefDef(tree)(name = nme.IMPLCLASS_CONSTRUCTOR)
3330
else tree
3431
}
35-
3632
}

0 commit comments

Comments
 (0)