Skip to content

Commit d2f8c67

Browse files
committed
Changes to owners in Mixin and Constructors
Two changes: 1. Replace changeOwer with changeOwnerAfter for code that moves into the $initial methods in Mixin. This is needed because otherwise subsequent transforms gets confused wrt new vs old owners. `i1131.scala` exhibits the problem. 2. Drop `transformSym` changed the owner of tenplate-local symbols to be the primary constructor. But that is done anyway with a "changeOwnerAfter" in `intoConstr`. So it is redundant and actually gets in the way with a `changeOwnerAfter` in `Mixin`. The faulty scenario is this: 1. The SymTransformer of Constructor is run on a constructor-local definition. The owner of that definition is set to <init> after phase Constructors. 2. The body of the definition is transformed in Mixin. The owner is set to the initializer method, but only for the interval between Mixin and Constructors. Changing to changeOwner in Mixin avoided that problem by duplicating the symbol but it runs into other problems. Fortunately, the solution is much simpler than the status quo: Two changeOwnerAfter calls and no SymTransformer.
1 parent db6c5eb commit d2f8c67

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

src/dotty/tools/dotc/transform/Constructors.scala

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import collection.mutable
2626
* - also moves private fields that are accessed only from constructor
2727
* into the constructor if possible.
2828
*/
29-
class Constructors extends MiniPhaseTransform with SymTransformer { thisTransform =>
29+
class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
3030
import tpd._
3131

3232
override def phaseName: String = "constructors"
@@ -99,18 +99,6 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
9999
}
100100
}
101101

102-
/** Symbols that are owned by either <local dummy> or a class field move into the
103-
* primary constructor.
104-
*/
105-
override def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = {
106-
def ownerBecomesConstructor(owner: Symbol): Boolean =
107-
(owner.isLocalDummy || owner.isTerm && !owner.is(MethodOrLazy)) &&
108-
owner.owner.isClass
109-
if (ownerBecomesConstructor(sym.owner))
110-
sym.copySymDenotation(owner = sym.owner.enclosingClass.primaryConstructor)
111-
else sym
112-
}
113-
114102
/** @return true if after ExplicitOuter, all references from this tree go via an
115103
* outer link, so no parameter accessors need to be rewired to parameters
116104
*/

src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
134134
val vsym = stat.symbol
135135
val isym = initializer(vsym)
136136
val rhs = Block(
137-
initBuf.toList.map(_.changeOwner(impl.symbol, isym)),
138-
stat.rhs.changeOwner(vsym, isym).wildcardToDefault)
137+
initBuf.toList.map(_.changeOwnerAfter(impl.symbol, isym, thisTransform)),
138+
stat.rhs.changeOwnerAfter(vsym, isym, thisTransform).wildcardToDefault)
139139
initBuf.clear()
140140
cpy.DefDef(stat)(rhs = EmptyTree) :: DefDef(isym, rhs) :: Nil
141141
case stat: DefDef if stat.symbol.isSetter =>

0 commit comments

Comments
 (0)