@@ -14,7 +14,7 @@ package scala.tools.nsc
14
14
package transform
15
15
16
16
import scala .annotation ._
17
- import scala .collection .mutable
17
+ import scala .collection .mutable , mutable . ListBuffer
18
18
import scala .reflect .internal .util .ListOfNil
19
19
import scala .tools .nsc .Reporting .WarningCategory
20
20
import symtab .Flags ._
@@ -29,8 +29,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
29
29
/** the following two members override abstract members in Transform */
30
30
val phaseName : String = " constructors"
31
31
32
- protected def newTransformer (unit : CompilationUnit ): AstTransformer =
33
- new ConstructorTransformer (unit)
32
+ protected def newTransformer (unit : CompilationUnit ): AstTransformer = new ConstructorTransformer (unit)
34
33
35
34
private val guardedCtorStats : mutable.Map [Symbol , List [Tree ]] = perRunCaches.newMap[Symbol , List [Tree ]]()
36
35
private val ctorParams : mutable.Map [Symbol , List [Symbol ]] = perRunCaches.newMap[Symbol , List [Symbol ]]()
@@ -155,8 +154,8 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
155
154
* Finally, the whole affair of eliding is avoided for DelayedInit subclasses,
156
155
* given that for them usually nothing gets elided anyway.
157
156
* That's a consequence from re-locating the post-super-calls statements from their original location
158
- * (the primary constructor) into a dedicated synthetic method that an anon-closure may invoke, as required by DelayedInit.
159
- *
157
+ * (the primary constructor) into a dedicated synthetic method that an anon-closure may invoke,
158
+ * as required by DelayedInit.
160
159
*/
161
160
private trait OmittablesHelper {
162
161
def computeOmittableAccessors (clazz : Symbol , defs : List [Tree ], auxConstructors : List [Tree ], @ unused constructor : List [Tree ]): Set [Symbol ] = {
@@ -337,7 +336,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
337
336
* `specializedStats` are replaced by the specialized assignment.
338
337
*/
339
338
private def mergeConstructors (genericClazz : Symbol , originalStats : List [Tree ], specializedStats : List [Tree ]): List [Tree ] = {
340
- val specBuf = new mutable. ListBuffer [Tree ]
339
+ val specBuf = ListBuffer .empty [Tree ]
341
340
specBuf ++= specializedStats
342
341
343
342
def specializedAssignFor (sym : Symbol ): Option [Tree ] =
@@ -466,11 +465,15 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
466
465
private val stats = impl.body // the transformed template body
467
466
468
467
// find and dissect primary constructor
469
- private val (primaryConstr, _primaryConstrParams, primaryConstrBody) = stats collectFirst {
470
- case dd@ DefDef (_, _, _, vps :: Nil , _, rhs : Block ) if dd.symbol.isPrimaryConstructor => (dd, vps map (_.symbol), rhs)
471
- } getOrElse {
472
- abort(" no constructor in template: impl = " + impl)
473
- }
468
+ private val (primaryConstr, _primaryConstrParams, primaryConstrBody) =
469
+ stats.collectFirst {
470
+ case dd @ DefDef (_, _, _, vps :: Nil , _, rhs : Block )
471
+ if dd.symbol.isPrimaryConstructor =>
472
+ (dd, vps.map(_.symbol), rhs)
473
+ }
474
+ .getOrElse {
475
+ abort(" no constructor in template: impl = " + impl)
476
+ }
474
477
475
478
def primaryConstrParams = _primaryConstrParams
476
479
def usesSpecializedField = intoConstructor.usesSpecializedField
@@ -594,7 +597,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
594
597
* - `classInitStats`: statements that go into the class initializer
595
598
*/
596
599
class Triage {
597
- private val defBuf, auxConstructorBuf, constrPrefixBuf, constrStatBuf, classInitStatBuf = new mutable. ListBuffer [Tree ]
600
+ private val defBuf, auxConstructorBuf, constrPrefixBuf, constrStatBuf, classInitStatBuf = ListBuffer .empty [Tree ]
598
601
599
602
triage()
600
603
@@ -617,8 +620,15 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
617
620
stat match {
618
621
case ValDef (mods, name, _, _) if mods.hasFlag(PRESUPER ) => // TODO trait presupers
619
622
// stat is the constructor-local definition of the field value
620
- val fields = presupers filter (_.getterName == name)
621
- assert(fields.length == 1 , s " expected exactly one field by name $name in $presupers of $clazz's early initializers " )
623
+ val fields = presupers.filter { v =>
624
+ val nm =
625
+ if (v.symbol.isPrivateLocal && v.symbol.hasFlag(EXPANDEDNAME ))
626
+ v.symbol.unexpandedName.dropLocal
627
+ else
628
+ v.getterName
629
+ nm == name
630
+ }
631
+ assert(fields.length == 1 , s " expected exactly one field by name $name in $presupers of $clazz's early initializers but saw $fields" )
622
632
val to = fields.head.symbol
623
633
624
634
if (memoizeValue(to)) constrStatBuf += mkAssign(to, Ident (stat.symbol))
@@ -789,7 +799,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
789
799
790
800
// Eliminate all field/accessor definitions that can be dropped from template
791
801
// We never eliminate delayed hooks or the constructors, so, only filter `defs`.
792
- val prunedStats = ( defs filterNot omittableStat) ::: delayedHookDefs ::: constructors
802
+ val prunedStats = defs. filterNot( omittableStat) ::: delayedHookDefs ::: constructors
793
803
794
804
val statsWithInitChecks =
795
805
if (settings.checkInit.value) {
0 commit comments