From adb112fec4b26a4bd930803c0b8b44f543a79863 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 11 Apr 2011 08:53:51 +0000 Subject: Closes #4380. No review. --- .../scala/tools/nsc/transform/Constructors.scala | 16 ++++++++++------ test/files/run/t4396.check | 1 + test/files/run/t4396.scala | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 1fb1cf11f9..3a9ebd0d9a 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -215,12 +215,13 @@ abstract class Constructors extends Transform with ast.TreeDSL { // the symbol is an outer accessor of a final class which does not override another outer accessor. ) def maybeOmittable(sym: Symbol) = sym.owner == clazz && ( sym.isParamAccessor && sym.isPrivateLocal || - sym.isOuterAccessor && sym.owner.isFinal && sym.allOverriddenSymbols.isEmpty + sym.isOuterAccessor && sym.owner.isFinal && sym.allOverriddenSymbols.isEmpty && + !(clazz isSubClass DelayedInitClass) ) // Is symbol known to be accessed outside of the primary constructor, // or is it a symbol whose definition cannot be omitted anyway? - def mustbeKept(sym: Symbol) = !maybeOmittable(sym) || accessedSyms(sym) + def mustbeKept(sym: Symbol) = !maybeOmittable(sym) || (accessedSyms contains sym) // A traverser to set accessedSyms and outerAccessors val accessTraverser = new Traverser { @@ -497,10 +498,10 @@ abstract class Constructors extends Transform with ast.TreeDSL { val getter = ensureGetter(tree.symbol) if (getter != NoSymbol) applyMethodTyper.typed { - atPos(tree.pos) { - Apply(Select(qual, getter), List()) - } + atPos(tree.pos) { + Apply(Select(qual, getter), List()) } + } else tree case Assign(lhs @ Select(qual, _), rhs) => val setter = ensureSetter(lhs.symbol) @@ -578,7 +579,10 @@ abstract class Constructors extends Transform with ast.TreeDSL { // Unlink all fields that can be dropped from class scope for (sym <- clazz.info.decls.toList) - if (!mustbeKept(sym)) clazz.info.decls unlink sym + if (!mustbeKept(sym)) { + println("dropping "+sym+sym.locationString) + clazz.info.decls unlink sym + } // Eliminate all field definitions that can be dropped from template treeCopy.Template(impl, impl.parents, impl.self, diff --git a/test/files/run/t4396.check b/test/files/run/t4396.check index b0b4014430..58f4fc5138 100644 --- a/test/files/run/t4396.check +++ b/test/files/run/t4396.check @@ -2,3 +2,4 @@ hallo constructor out:22 bye +foo diff --git a/test/files/run/t4396.scala b/test/files/run/t4396.scala index 9911f323a5..d67eaa378e 100644 --- a/test/files/run/t4396.scala +++ b/test/files/run/t4396.scala @@ -1,3 +1,4 @@ +// #43896 trait M extends DelayedInit { def delayedInit(body : => Unit) { println("hallo") @@ -13,6 +14,22 @@ class C(init : Int) extends M { println("out:"+x) } +// #4380 +object Main { + def main(argv: Array[String]) { + class Bip { + class Foo { override def toString() = "foo" } + object Main extends App { + val cbn = new Foo() + } + Main.main(Array()) + println(Main.cbn) + } + new Bip + } +} + object Test extends App { new C(22) + Main.main(Array()) } -- cgit v1.2.3