aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/Constructors.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-06-19 23:12:46 +0200
committerMartin Odersky <odersky@gmail.com>2015-06-19 23:12:57 +0200
commit9bf44f867c1a9f4625dd7fac9575c3e74373402b (patch)
treef60948565b2200e3d93dc0873fcdd0a279ee1f0c /src/dotty/tools/dotc/transform/Constructors.scala
parentf3a676a33e075b93d99689f26e76632e57a4d8c3 (diff)
downloaddotty-9bf44f867c1a9f4625dd7fac9575c3e74373402b.tar.gz
dotty-9bf44f867c1a9f4625dd7fac9575c3e74373402b.tar.bz2
dotty-9bf44f867c1a9f4625dd7fac9575c3e74373402b.zip
Map outer accessors to outer paramaters
Map references to outer accessors in secondary constructors to outer parameters. This was the second source of "reference to this before super call" errors.
Diffstat (limited to 'src/dotty/tools/dotc/transform/Constructors.scala')
-rw-r--r--src/dotty/tools/dotc/transform/Constructors.scala12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/Constructors.scala b/src/dotty/tools/dotc/transform/Constructors.scala
index 100e9ff21..d078bab1d 100644
--- a/src/dotty/tools/dotc/transform/Constructors.scala
+++ b/src/dotty/tools/dotc/transform/Constructors.scala
@@ -156,6 +156,16 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
val constrStats, clsStats = new mutable.ListBuffer[Tree]
+ /** Map outer getters $outer and outer accessors $A$B$$$outer to the given outer parameter. */
+ def mapOuter(outerParam: Symbol) = new TreeMap {
+ override def transform(tree: Tree)(implicit ctx: Context) = tree match {
+ case Apply(fn, Nil) if fn.symbol.is(OuterAccessor) || fn.symbol.isGetter && fn.symbol.name == nme.OUTER =>
+ ref(outerParam)
+ case _ =>
+ super.transform(tree)
+ }
+ }
+
// 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 {
@@ -174,6 +184,8 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
owner = constr.symbol).installAfter(thisTransform)
constrStats += intoConstr(stat, sym)
}
+ case DefDef(nme.CONSTRUCTOR, _, ((outerParam @ ValDef(nme.OUTER, _, _)) :: _) :: Nil, _, _) =>
+ clsStats += mapOuter(outerParam.symbol).transform(stat)
case _: DefTree =>
clsStats += stat
case _ =>