aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/Constructors.scala
blob: 33d742a17208cc28bfe0c18a411039285caea241 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package dotty.tools.dotc.transform

import TreeTransforms._
import dotty.tools.dotc.ast.tpd._
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.StdNames._

/** This transform moves initializers from body to constructor.
 *  Right now it's a dummy.
 *  Awaiting for real implemetation
 */
class Constructors extends MiniPhaseTransform {

  override def name: String = "constructors"
  override def transformDefDef(tree: DefDef)(implicit ctx: Context, info: TransformerInfo): Tree = {
    if(tree.symbol.isClassConstructor) {
      val claz = tree.symbol.enclosingClass.asClass
      val zuper = claz.info.parents.head.typeSymbol
      cpy.DefDef(tree, tree.mods, tree.name, tree.tparams, tree.vparamss, tree.tpt, rhs = {
        val parentCall =
          Super(This(claz), tpnme.EMPTY, true).select(zuper.primaryConstructor).appliedToNone
        if(tree.rhs.isEmpty) parentCall
        else Block(List(parentCall), tree.rhs)

      })
    } else tree
  }
}