Skip to content

Commit 7577c7a

Browse files
authored
Merge pull request scala#9259 from lrytz/t12096
2 parents 262f5f2 + e79b6ef commit 7577c7a

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

src/compiler/scala/tools/nsc/transform/Constructors.scala

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
172172
// class Outer { def test = {class LocalParent; class LocalChild extends LocalParent } }
173173
//
174174
// See run/t9408.scala for related test cases.
175-
def omittableParamAcc(sym: Symbol) = sym.isParamAccessor && sym.isPrivateLocal
175+
def omittableParamAcc(sym: Symbol) = sym.isParamAccessor && sym.isPrivateLocal && !sym.isVariable
176176
def omittableOuterAcc(sym: Symbol) = isEffectivelyFinal && sym.isOuterAccessor && !sym.isOverridingSymbol
177177
val omittables = mutable.Set.empty[Symbol] ++ (decls filter (sym => omittableParamAcc(sym) || omittableOuterAcc(sym))) // the closure only captures isEffectivelyFinal
178178

@@ -192,28 +192,10 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
192192
}
193193
}
194194
}
195-
class DetectAssigns(targets: mutable.Set[Symbol]) extends Traverser {
196-
override def traverse(tree: Tree): Unit = if (targets.nonEmpty) {
197-
tree match {
198-
case Assign(lhs, _) if targets(lhs.symbol) =>
199-
targets -= lhs.symbol
200-
omittables -= lhs.symbol
201-
super.traverse(tree)
202-
case _ => super.traverse(tree)
203-
}
204-
}
205-
}
206195

207196
if (omittables.nonEmpty)
208197
(defs.iterator ++ auxConstructors.iterator) foreach detectUsages.traverse
209198

210-
if (omittables.nonEmpty) {
211-
val omittedVars = omittables.filter(_.isVariable)
212-
if (omittedVars.nonEmpty) {
213-
val detector = new DetectAssigns(omittedVars)
214-
constructor.foreach(detector.traverse)
215-
}
216-
}
217199
omittables.toSet
218200
}
219201
} // OmittablesHelper

test/files/run/t12002.check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
good boy!
2+
List()
3+
List()
4+
List(private int C.x)
5+
List(private int D.x)
6+
List(private int E.x)
7+
List(private int F.x)
8+
List(private int G.x)
9+
List(private final int H.x)
10+
List(private int I.x)

test/files/run/t12002.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
class C(private[this] var c: String) {
1+
class C0(private[this] var c: String) {
22
private[this] var x: String = _
33
c = "good"
44
x = c + " boy!"
55
override def toString = x
66
}
77

8+
class A(x: Int) { assert(x == 1) } // elided
9+
class B(private[this] val x: Int) { assert(x == 1) } // elided
10+
class C(private[this] var x: Int) { } // kept
11+
class D(private[this] var x: Int) { assert(x == 1) } // kept
12+
class E(private[this] var x: Int) { x = 2 } // kept
13+
class F(private[this] var x: Int) { x = 2; assert(x == 2) } // kept
14+
class G(private[this] var x: Int) { x = 2; assert(x == 2); def m() = assert(x == 2, "m" + x); m() } // kept
15+
class H(private val x: Int) { } // kept
16+
class I(private var x: Int) { } // kept
17+
818
object Test {
9-
def main(args: Array[String]) = println {
10-
new C("bad")
19+
def fs(o: AnyRef) = println(o.getClass.getDeclaredFields.toList)
20+
def main(args: Array[String]): Unit = {
21+
println(new C0("bad"))
22+
List(new A(1), new B(1), new C(1), new D(1), new E(1), new F(1), new G(1), new H(1), new I(1)).foreach(fs)
1123
}
1224
}

0 commit comments

Comments
 (0)