@@ -73,7 +73,7 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
73
73
74
74
override def transform (tree : Tree ): Tree = {
75
75
tree match {
76
- case cd @ ClassDef (mods0, name0, tparams0, impl0) if ! cd.symbol.isInterface && ! isPrimitiveValueClass(cd.symbol) =>
76
+ case cd @ ClassDef (mods0, name0, tparams0, impl0) if ! isPrimitiveValueClass(cd.symbol) =>
77
77
if (cd.symbol eq AnyValClass ) {
78
78
cd
79
79
}
@@ -456,7 +456,7 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
456
456
457
457
// find and dissect primary constructor
458
458
private val (primaryConstr, _primaryConstrParams, primaryConstrBody) = stats collectFirst {
459
- case dd@ DefDef (_, _, _, vps :: Nil , _, rhs : Block ) if dd.symbol.isPrimaryConstructor => (dd, vps map (_.symbol), rhs)
459
+ case dd@ DefDef (_, _, _, vps :: Nil , _, rhs : Block ) if dd.symbol.isPrimaryConstructor || dd.symbol.isMixinConstructor => (dd, vps map (_.symbol), rhs)
460
460
} getOrElse {
461
461
abort(" no constructor in template: impl = " + impl)
462
462
}
@@ -545,10 +545,14 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
545
545
}
546
546
547
547
// Create an assignment to class field `to` with rhs `from`
548
- def mkAssign (to : Symbol , from : Tree ): Tree =
549
- localTyper.typedPos(to.pos) {
550
- Assign (Select (This (clazz), to), from)
551
- }
548
+ def mkAssign (to : Symbol , from : Tree ): Tree = {
549
+ val tree = if (to.owner.isTrait) {
550
+ val setter = to.setterIn(to.owner)
551
+ gen.mkMethodCall(This (to.owner), setter, Nil , from :: Nil )
552
+ } else Assign (Select (This (clazz), to), from)
553
+
554
+ localTyper.typedPos(to.pos)(tree)
555
+ }
552
556
553
557
// Create code to copy parameter to parameter accessor field.
554
558
// If parameter is $outer, check that it is not null so that we NPE
@@ -629,8 +633,12 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
629
633
// Triage methods -- they all end up in the template --
630
634
// regular ones go to `defBuf`, secondary contructors go to `auxConstructorBuf`.
631
635
// The primary constructor is dealt with separately (we're massaging it here).
632
- case _ : DefDef if statSym.isPrimaryConstructor => ()
636
+ case _ : DefDef if statSym.isPrimaryConstructor || statSym.isMixinConstructor => ()
633
637
case _ : DefDef if statSym.isConstructor => auxConstructorBuf += stat
638
+ case stat : DefDef if stat.symbol.owner.isTrait && stat.symbol.hasAllFlags(STABLE | ACCESSOR ) && stat.rhs != EmptyTree =>
639
+ val emitField = memoizeValue(statSym)
640
+ moveEffectToCtor(stat.mods, stat.rhs, if (emitField) statSym else NoSymbol ) // TODO: ever NoSymbol?
641
+ defBuf += deriveDefDef(stat)(_ => EmptyTree )
634
642
case stat : DefDef =>
635
643
defBuf += stat
636
644
0 commit comments