diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-12-19 08:17:43 -0800 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-12-19 08:17:43 -0800 |
commit | fa20a1c9c479ceff93075fca40be6ee89a97e4c8 (patch) | |
tree | 895b5359fbb2b4b4784502501011ec8f1dfcbaf7 /src | |
parent | fc8bfb4b7564151eecb721c831f3f7d0655f2b1e (diff) | |
parent | 3b8b24a48b1ebc81eb6154c4f8c8c8d82ac3de48 (diff) | |
download | scala-fa20a1c9c479ceff93075fca40be6ee89a97e4c8.tar.gz scala-fa20a1c9c479ceff93075fca40be6ee89a97e4c8.tar.bz2 scala-fa20a1c9c479ceff93075fca40be6ee89a97e4c8.zip |
Merge pull request #3234 from retronym/ticket/5508-3
Fix crasher with private[this] in nested traits
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Flatten.scala | 28 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Mixin.scala | 16 |
2 files changed, 23 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala index e31211d321..b4329965fc 100644 --- a/src/compiler/scala/tools/nsc/transform/Flatten.scala +++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala @@ -100,23 +100,36 @@ abstract class Flatten extends InfoTransform { /** Buffers for lifted out classes */ private val liftedDefs = perRunCaches.newMap[Symbol, ListBuffer[Tree]]() - override def transform(tree: Tree): Tree = { + override def transform(tree: Tree): Tree = postTransform { tree match { case PackageDef(_, _) => liftedDefs(tree.symbol.moduleClass) = new ListBuffer + super.transform(tree) case Template(_, _, _) if tree.symbol.isDefinedInPackage => liftedDefs(tree.symbol.owner) = new ListBuffer + super.transform(tree) + case ClassDef(_, _, _, _) if tree.symbol.isNestedClass => + // SI-5508 Ordering important. In `object O { trait A { trait B } }`, we want `B` to appear after `A` in + // the sequence of lifted trees in the enclosing package. Why does this matter? Currently, mixin + // needs to transform `A` first to a chance to create accessors for private[this] trait fields + // *before* it transforms inner classes that refer to them. This also fixes SI-6231. + // + // Alternative solutions + // - create the private[this] accessors eagerly in Namer (but would this cover private[this] fields + // added later phases in compilation?) + // - move the accessor creation to the Mixin info transformer + val liftedBuffer = liftedDefs(tree.symbol.enclosingTopLevelClass.owner) + val index = liftedBuffer.length + liftedBuffer.insert(index, super.transform(tree)) + EmptyTree case _ => + super.transform(tree) } - postTransform(super.transform(tree)) } private def postTransform(tree: Tree): Tree = { val sym = tree.symbol val tree1 = tree match { - case ClassDef(_, _, _, _) if sym.isNestedClass => - liftedDefs(sym.enclosingTopLevelClass.owner) += tree - EmptyTree case Select(qual, name) if sym.isStaticModule && !sym.isTopLevel => exitingFlatten { atPos(tree.pos) { @@ -134,7 +147,10 @@ abstract class Flatten extends InfoTransform { /** Transform statements and add lifted definitions to them. */ override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = { val stats1 = super.transformStats(stats, exprOwner) - if (currentOwner.isPackageClass) stats1 ::: liftedDefs(currentOwner).toList + if (currentOwner.isPackageClass) { + val lifted = liftedDefs(currentOwner).toList + stats1 ::: lifted + } else stats1 } } diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 6da971338f..89f9cb4b06 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -1207,21 +1207,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { val iface = toInterface(sym.owner.tpe).typeSymbol val ifaceGetter = sym getter iface - def si6231Restriction() { - // See SI-6231 comments in LamdaLift for ideas on how to lift the restriction. - val msg = sm"""Implementation restriction: local ${iface.fullLocationString} is unable to automatically capture the - |free variable ${sym} on behalf of ${currentClass}. You can manually assign it to a val inside the trait, - |and refer to that val in ${currentClass}. For more details, see SI-6231.""" - reporter.error(tree.pos, msg) - } - - if (ifaceGetter == NoSymbol) { - if (sym.isParamAccessor) { - si6231Restriction() - EmptyTree - } - else abort("No getter for " + sym + " in " + iface) - } + if (ifaceGetter == NoSymbol) abort("No getter for " + sym + " in " + iface) else typedPos(tree.pos)((qual DOT ifaceGetter)()) case Assign(Apply(lhs @ Select(qual, _), List()), rhs) => |