diff options
author | Paul Phillips <paulp@improving.org> | 2013-03-25 14:26:15 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-03-25 14:26:15 -0700 |
commit | 5e8f4b2596c31eeacec8a30945cbee1841769ad7 (patch) | |
tree | 417b5f4a8126f023ae607ee195841837e3be7291 /src/compiler | |
parent | e17121d16950545d7e70ee255556ad11409bf8c3 (diff) | |
parent | cd9e03af8d61e7def5df2a0958de31ca0c163780 (diff) | |
download | scala-5e8f4b2596c31eeacec8a30945cbee1841769ad7.tar.gz scala-5e8f4b2596c31eeacec8a30945cbee1841769ad7.tar.bz2 scala-5e8f4b2596c31eeacec8a30945cbee1841769ad7.zip |
Merge pull request #2270 from retronym/ticket/7246-2
SI-7246 Make $outer pointer elision Java aware
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index f6ee7be511..970519ab7c 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -45,26 +45,24 @@ abstract class ExplicitOuter extends InfoTransform private def isInner(clazz: Symbol) = !clazz.isPackageClass && !clazz.outerClass.isStaticOwner - private def haveSameOuter(parent: Type, clazz: Symbol) = parent match { - case TypeRef(pre, sym, _) => - val owner = clazz.owner + private def haveSameOuter(parent: Type, clazz: Symbol) = { + val owner = clazz.owner + val parentSym = parent.typeSymbol - //println(s"have same outer $parent $clazz $sym ${sym.owner} $owner $pre") - - sym.isClass && owner.isClass && - (owner isSubClass sym.owner) && - owner.thisType =:= pre - - case _ => false + parentSym.isClass && owner.isClass && + (owner isSubClass parentSym.owner) && + owner.thisType =:= parent.prefix } /** Does given clazz define an outer field? */ def hasOuterField(clazz: Symbol) = { - val parents = clazz.info.parents + val parent = clazz.info.firstParent - isInner(clazz) && !clazz.isTrait && { - parents.isEmpty || !haveSameOuter(parents.head, clazz) - } + // space optimization: inherit the $outer pointer from the parent class if + // we know that it will point to the correct instance. + def canReuseParentOuterField = !parent.typeSymbol.isJavaDefined && haveSameOuter(parent, clazz) + + isInner(clazz) && !clazz.isTrait && !canReuseParentOuterField } private def outerField(clazz: Symbol): Symbol = { |