Skip to content

Commit afb2195

Browse files
committed
Constructors stub
1 parent bf9ae99 commit afb2195

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Compiler {
2121
List(
2222
List(new FrontEnd),
2323
List(new LazyValsCreateCompanionObjects,
24+
/* new Constructors, */
2425
new TailRec), //force separataion between lazyVals and LVCreateCO
2526
List(new PatternMatcher,
2627
new LazyValTranformContext().transformer,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dotty.tools.dotc.transform
2+
3+
import TreeTransforms._
4+
import dotty.tools.dotc.ast.tpd._
5+
import dotty.tools.dotc.core.Contexts.Context
6+
import dotty.tools.dotc.core.StdNames._
7+
8+
/** This transform moves initializers from body to constructor.
9+
* Right now it's a dummy.
10+
* Awaiting for real implemetation
11+
*/
12+
class Constructors extends TreeTransform {
13+
14+
override def name: String = "constructors"
15+
override def transformDefDef(tree: DefDef)(implicit ctx: Context, info: TransformerInfo): Tree = {
16+
if(tree.symbol.isClassConstructor) {
17+
val claz = tree.symbol.enclosingClass.asClass
18+
val zuper = claz.info.parents.head.typeSymbol
19+
cpy.DefDef(tree, tree.mods, tree.name, tree.tparams, tree.vparamss, tree.tpt, rhs = {
20+
val parentCall = Apply(Select(Super(This(claz), tpnme.EMPTY, true), zuper.primaryConstructor), Nil)
21+
if(tree.rhs.isEmpty) parentCall
22+
else Block(List(parentCall), tree.rhs)
23+
24+
})
25+
} else tree
26+
}
27+
}

0 commit comments

Comments
 (0)