diff options
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 15 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/Constructors.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/GettersSetters.scala | 8 |
4 files changed, 28 insertions, 20 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index 63f79c8d3..239b38338 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -24,17 +24,6 @@ class Compiler { * all refs to it would become outdated - they could not be dereferenced in the * new phase. * - * As an example, addGetters would change a field - * - * val x: T - * - * to a method - * - * def x: T - * - * but this would affect the signature of `x` (goes from NotAMethod to a method - * signature). So we can't do this before erasure. - * * After erasure, signature changing denot-transformers are OK because erasure * will make sure that only term refs with fixed SymDenotations survive beyond it. This * is possible because: @@ -61,7 +50,8 @@ class Compiler { new Splitter), List(new ElimByName, new InterceptedMethods, - new Literalize), + new Literalize, + new GettersSetters), List(new Erasure), List(new CapturedVars, new Constructors)/*, List(new LambdaLift)*/ diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 45e0aff54..2a6ec9d78 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -2,8 +2,8 @@ package dotty.tools package dotc package ast +import transform.SymUtils._ import core._ -import dotty.tools.dotc.transform.TypeUtils import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._ import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._ import Denotations._, Decorators._ @@ -599,6 +599,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def or(that: Tree)(implicit ctx: Context): Tree = tree.select(defn.Boolean_||).appliedTo(that) + def becomes(rhs: Tree)(implicit ctx: Context): Tree = + if (tree.symbol is Method) { + val setr = tree match { + case Ident(_) => + val setter = tree.symbol.setter + assert(setter.exists, tree.symbol.showLocated) + ref(tree.symbol.setter) + case Select(qual, _) => qual.select(tree.symbol.setter) + } + setr.appliedTo(rhs) + } + else Assign(tree, rhs) + // --- Higher order traversal methods ------------------------------- def foreachSubTree(f: Tree => Unit): Unit = { //TODO should go in tpd. diff --git a/src/dotty/tools/dotc/transform/Constructors.scala b/src/dotty/tools/dotc/transform/Constructors.scala index 9cb348dff..7bde1ba4f 100644 --- a/src/dotty/tools/dotc/transform/Constructors.scala +++ b/src/dotty/tools/dotc/transform/Constructors.scala @@ -16,6 +16,7 @@ import SymDenotations._ import Types._ import Decorators._ import DenotTransformers._ +import util.Positions._ import collection.mutable /** This transform @@ -76,7 +77,7 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor case _ => } assert(accessors.hasSameLengthAs(vparamsWithOuter), - i"lengths differ for $cls, param accs = $accessors, params = $vparamsWithOuter") + i"lengths differ for $cls, param accs = $accessors, params = ($vparamsWithOuter%, %)") } val paramSyms = vparamsWithOuter map (_.symbol) @@ -177,6 +178,10 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor val constrStats, clsStats = new mutable.ListBuffer[Tree] + def assign(vble: Symbol, rhs: Tree): Tree = + if (cls is Trait) ref(vble.setter).appliedTo(rhs) + else Assign(ref(vble), rhs) + // Split class body into statements that go into constructor and // definitions that are kept as members of the class. def splitStats(stats: List[Tree]): Unit = stats match { @@ -186,7 +191,7 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor val sym = stat.symbol if (isRetained(sym)) { if (!rhs.isEmpty && !isWildcardArg(rhs)) - constrStats += Assign(ref(sym), intoConstr(rhs)).withPos(stat.pos) + constrStats += assign(sym, intoConstr(rhs)).withPos(stat.pos) clsStats += cpy.ValDef(stat)(rhs = EmptyTree) } else if (!rhs.isEmpty) { @@ -210,7 +215,7 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor // The initializers for the retained accessors */ val copyParams = accessorFields.filter(isRetained).map(acc => - Assign(ref(acc), ref(acc.subst(accessors, paramSyms))).withPos(tree.pos)) + assign(acc, ref(acc.subst(accessors, paramSyms))).withPos(tree.pos)) // Drop accessors that are not retained from class scope val dropped = usage.dropped diff --git a/src/dotty/tools/dotc/transform/GettersSetters.scala b/src/dotty/tools/dotc/transform/GettersSetters.scala index 05c706419..772a63e52 100644 --- a/src/dotty/tools/dotc/transform/GettersSetters.scala +++ b/src/dotty/tools/dotc/transform/GettersSetters.scala @@ -44,7 +44,7 @@ class GettersSetters extends MiniPhaseTransform with SymTransformer { thisTransf override def treeTransformPhase = thisTransform.next override def transformSym(d: SymDenotation)(implicit ctx: Context): SymDenotation = { - /* def noGetterNeeded = + def noGetterNeeded = d.is(Method | Param | JavaDefined) || d.initial.asInstanceOf[SymDenotation].is(PrivateLocal) && !d.owner.is(Trait) || d.is(Module) && d.isStatic || @@ -56,9 +56,9 @@ class GettersSetters extends MiniPhaseTransform with SymTransformer { thisTransf initFlags = d.flags | maybeStable | AccessorCreationFlags, info = ExprType(d.info)) } - else */ d + else d } -/* + override def transformValDef(tree: ValDef)(implicit ctx: Context, info: TransformerInfo): Tree = { if (tree.symbol is Method) { val getter = tree.symbol.asTerm @@ -114,5 +114,5 @@ class GettersSetters extends MiniPhaseTransform with SymTransformer { thisTransf override def transformAssign(tree: Assign)(implicit ctx: Context, info: TransformerInfo): Tree = if (tree.lhs.symbol is Method) tree.lhs.becomes(tree.rhs) - else tree*/ + else tree }
\ No newline at end of file |