diff options
author | Martin Odersky <odersky@gmail.com> | 2016-03-11 16:13:31 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-03-12 14:25:02 +0100 |
commit | dad9dfc2cc83e58fbe59f8cffd28ec1180d6fab1 (patch) | |
tree | 0fe7f54323294cc3da9b9b1aa3fb1c19c9f02f87 | |
parent | 69b07e2466ae96c37066ee02c7d45b9b52417342 (diff) | |
download | dotty-dad9dfc2cc83e58fbe59f8cffd28ec1180d6fab1.tar.gz dotty-dad9dfc2cc83e58fbe59f8cffd28ec1180d6fab1.tar.bz2 dotty-dad9dfc2cc83e58fbe59f8cffd28ec1180d6fab1.zip |
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.
-rw-r--r-- | src/dotty/tools/dotc/transform/Constructors.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/Mixin.scala | 4 |
2 files changed, 3 insertions, 15 deletions
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 <local dummy> 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 => |