diff options
author | Paul Phillips <paulp@improving.org> | 2012-03-20 10:35:10 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-03-28 14:02:54 -0700 |
commit | 399bd6240f775583ee9709311bd0b02e8359c15c (patch) | |
tree | 9018bea9794eedd95aaf9f1c6ca5900a7b2f06fd /test/files/run | |
parent | 97f03245d9646b9ade43418dee7dc0d2a6203ce7 (diff) | |
download | scala-399bd6240f775583ee9709311bd0b02e8359c15c.tar.gz scala-399bd6240f775583ee9709311bd0b02e8359c15c.tar.bz2 scala-399bd6240f775583ee9709311bd0b02e8359c15c.zip |
Never write final fields outside of constructors.
Closes SI-3569, SI-3770.
Also threw in experimental -Yoverride-vars. It's not robust.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/finalvar.check | 6 | ||||
-rw-r--r-- | test/files/run/finalvar.flags | 1 | ||||
-rw-r--r-- | test/files/run/finalvar.scala | 37 |
3 files changed, 44 insertions, 0 deletions
diff --git a/test/files/run/finalvar.check b/test/files/run/finalvar.check new file mode 100644 index 0000000000..2496293972 --- /dev/null +++ b/test/files/run/finalvar.check @@ -0,0 +1,6 @@ +(2,2,2,2,1) +(2,2,2,2) +(2,2,2,2,1001) +(2,2,2,2) +2 +10 diff --git a/test/files/run/finalvar.flags b/test/files/run/finalvar.flags new file mode 100644 index 0000000000..aee3039bec --- /dev/null +++ b/test/files/run/finalvar.flags @@ -0,0 +1 @@ +-Yoverride-vars -Yinline
\ No newline at end of file diff --git a/test/files/run/finalvar.scala b/test/files/run/finalvar.scala new file mode 100644 index 0000000000..010813e520 --- /dev/null +++ b/test/files/run/finalvar.scala @@ -0,0 +1,37 @@ +object Final { + class X(final var x: Int) { } + def f = new X(0).x += 1 +} + +class A { + var x = 1 + def y0 = x + def y1 = this.x + def y2 = (this: A).x +} + +class B extends A { + override def x = 2 + def z = super.x +} + +object Test { + def main(args: Array[String]): Unit = { + Final.f + val a = new B + println((a.x, a.y0, a.y1, a.y2, a.z)) + val a0: A = a + println((a0.x, a0.y0, a0.y1, a0.y2)) + a.x = 1001 + println((a.x, a.y0, a.y1, a.y2, a.z)) + println((a0.x, a0.y0, a0.y1, a0.y2)) + + val d = new D + println(d.w) + d.ten + println(d.w) + } +} + +class C { var w = 1 ; def ten = this.w = 10 } +class D extends C { override var w = 2 }
\ No newline at end of file |