diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-12-06 12:48:30 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2016-12-06 12:48:30 +0100 |
commit | 34dad77513d08535adaf26989bd0cd84993ceab1 (patch) | |
tree | 5fb4e31c2ca9f9d2c5c7f4eb365d6381c0367f3f /src/compiler | |
parent | ee1c02b374a4b8a053e9a8b14af5e205afa67e14 (diff) | |
download | scala-34dad77513d08535adaf26989bd0cd84993ceab1.tar.gz scala-34dad77513d08535adaf26989bd0cd84993ceab1.tar.bz2 scala-34dad77513d08535adaf26989bd0cd84993ceab1.zip |
SI-10093 don't move member traits to constructor body in constructors
Fixes a regression introduced in c8e6050. Member traits with only
abstract definitions (`isInterface`) were moved into the primary
constructor by mistake. (Flatten moved the classes back.)
The member trait was duplicated into the constructor of specialized
subclasses, causing it to be generated multiple times.
Also removes some unnecessary `isMixinConstructor` checks: the mixin
constructor is always the primary constructor.
This commit also clarifies (and tests) what `isInterface` means: for
scala-defined traits, it means there are only abstract members. For
java-defined interfaces, it is always true.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Constructors.scala | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 92823bafb2..231a3e4c64 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -462,7 +462,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme // find and dissect primary constructor private val (primaryConstr, _primaryConstrParams, primaryConstrBody) = stats collectFirst { - case dd@DefDef(_, _, _, vps :: Nil, _, rhs: Block) if dd.symbol.isPrimaryConstructor || dd.symbol.isMixinConstructor => (dd, vps map (_.symbol), rhs) + case dd@DefDef(_, _, _, vps :: Nil, _, rhs: Block) if dd.symbol.isPrimaryConstructor => (dd, vps map (_.symbol), rhs) } getOrElse { abort("no constructor in template: impl = " + impl) } @@ -646,14 +646,14 @@ abstract class Constructors extends Statics with Transform with TypingTransforme stat match { // recurse on class definition, store in defBuf - case _: ClassDef if !statSym.isInterface => - defBuf += new ConstructorTransformer(unit).transform(stat) + case _: ClassDef => + if (statSym.isInterface) defBuf += stat + else defBuf += new ConstructorTransformer(unit).transform(stat) // primary constructor is already tracked as `primaryConstr` // non-primary constructors go to auxConstructorBuf - // mixin constructors are suppressed (!?!?) case _: DefDef if statSym.isConstructor => - if ((statSym ne primaryConstrSym) && !statSym.isMixinConstructor) auxConstructorBuf += stat + if (statSym ne primaryConstrSym) auxConstructorBuf += stat // If a val needs a field, an empty valdef goes into the template. // Except for lazy and ConstantTyped vals, the field is initialized by an assignment in: |