From dad9dfc2cc83e58fbe59f8cffd28ec1180d6fab1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 11 Mar 2016 16:13:31 +0100 Subject: 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 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. --- src/dotty/tools/dotc/transform/Constructors.scala | 14 +------------- src/dotty/tools/dotc/transform/Mixin.scala | 4 ++-- 2 files changed, 3 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/transform/Constructors.scala b/src/dotty/tools/dotc/transform/Constructors.scala index b6ebd7d90..44638ce48 100644 --- a/src/dotty/tools/dotc/transform/Constructors.scala +++ b/src/dotty/tools/dotc/transform/Constructors.scala @@ -26,7 +26,7 @@ import collection.mutable * - also moves private fields that are accessed only from constructor * into the constructor if possible. */ -class Constructors extends MiniPhaseTransform with SymTransformer { thisTransform => +class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform => import tpd._ override def phaseName: String = "constructors" @@ -99,18 +99,6 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor } } - /** Symbols that are owned by either or a class field move into the - * primary constructor. - */ - override def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = { - def ownerBecomesConstructor(owner: Symbol): Boolean = - (owner.isLocalDummy || owner.isTerm && !owner.is(MethodOrLazy)) && - owner.owner.isClass - if (ownerBecomesConstructor(sym.owner)) - sym.copySymDenotation(owner = sym.owner.enclosingClass.primaryConstructor) - else sym - } - /** @return true if after ExplicitOuter, all references from this tree go via an * outer link, so no parameter accessors need to be rewired to parameters */ diff --git a/src/dotty/tools/dotc/transform/Mixin.scala b/src/dotty/tools/dotc/transform/Mixin.scala index 32b268fc7..d9e0c7476 100644 --- a/src/dotty/tools/dotc/transform/Mixin.scala +++ b/src/dotty/tools/dotc/transform/Mixin.scala @@ -134,8 +134,8 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform => val vsym = stat.symbol val isym = initializer(vsym) val rhs = Block( - initBuf.toList.map(_.changeOwner(impl.symbol, isym)), - stat.rhs.changeOwner(vsym, isym).wildcardToDefault) + initBuf.toList.map(_.changeOwnerAfter(impl.symbol, isym, thisTransform)), + stat.rhs.changeOwnerAfter(vsym, isym, thisTransform).wildcardToDefault) initBuf.clear() cpy.DefDef(stat)(rhs = EmptyTree) :: DefDef(isym, rhs) :: Nil case stat: DefDef if stat.symbol.isSetter => -- cgit v1.2.3