Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9226 from lrytz/t12002b
Keep `private[this] var` class parameter fields that are only read
- Loading branch information
Showing
3 changed files
with
25 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
good boy! | ||
List() | ||
List() | ||
List(private int C.x) | ||
List(private int D.x) | ||
List(private int E.x) | ||
List(private int F.x) | ||
List(private int G.x) | ||
List(private final int H.x) | ||
List(private int I.x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
// cf t6880 | ||
class C(private[this] var c: String) { | ||
class C0(private[this] var c: String) { | ||
private[this] var x: String = _ | ||
c = "good" | ||
x = c + " boy!" | ||
override def toString = x | ||
} | ||
|
||
class A(x: Int) { assert(x == 1) } // elided | ||
class B(private[this] val x: Int) { assert(x == 1) } // elided | ||
class C(private[this] var x: Int) { } // kept | ||
class D(private[this] var x: Int) { assert(x == 1) } // kept | ||
class E(private[this] var x: Int) { x = 2 } // kept | ||
class F(private[this] var x: Int) { x = 2; assert(x == 2) } // kept | ||
class G(private[this] var x: Int) { x = 2; assert(x == 2); def m() = assert(x == 2, "m" + x); m() } // kept | ||
class H(private val x: Int) { } // kept | ||
class I(private var x: Int) { } // kept | ||
|
||
object Test { | ||
def main(args: Array[String]) = println { | ||
new C("bad") | ||
def fs(o: AnyRef) = println(o.getClass.getDeclaredFields.toList) | ||
def main(args: Array[String]): Unit = { | ||
println(new C0("bad")) | ||
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) | ||
} | ||
} | ||
|
||
// was | ||
// java.lang.NoSuchFieldError: c | ||
// at C.<init>(t12002.scala:6) |