Skip to content

Commit 02fb348

Browse files
committed
Fix for public final fields.
References SI-3569. Probably needs refinement.
1 parent f2ffc5b commit 02fb348

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
824824

825825
def genField(f: IField) {
826826
debuglog("Adding field: " + f.symbol.fullName)
827+
827828
val jfield = jclass.addNewField(
828829
javaFlags(f.symbol) | javaFieldFlags(f.symbol),
829830
javaName(f.symbol),
@@ -1904,6 +1905,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
19041905
((sym.rawflags & (Flags.FINAL | Flags.MODULE)) != 0)
19051906
&& !sym.enclClass.isInterface
19061907
&& !sym.isClassConstructor
1908+
&& (sym.isLazy || sym.getter.isPrivate || !sym.isMutable) // fix for SI-3569, is it sufficient?
19071909
)
19081910

19091911
mkFlags(

test/files/run/t3569.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1
2+
private final int Test$X.x2
3+
private final int Test$X.x3
4+
private final int Test$X.x5
5+
private final int Test$X.x6
6+
private final int Test$X.x7
7+
private int Test$X.x4
8+
private volatile int Test$X.bitmap$priv$0
9+
public int Test$X.x
10+
public volatile int Test$X.bitmap$0
11+
private int Test$Y.z1
12+
public int Test$Y.x
13+
public int Test$Y.y
14+
public int Test$Y.z2

test/files/run/t3569.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yinline

test/files/run/t3569.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
object Test {
2+
lazy val lv = scala.util.Random.nextInt()
3+
4+
class X(final var x: Int) {
5+
final private[this] var x2: Int = 0
6+
final var x3: Int = 0
7+
private[this] var x4: Int = 0
8+
final private[this] var x5: Int = 0
9+
final lazy val x6: Int = 0
10+
final private[this] lazy val x7: Int = 0
11+
}
12+
case class Y(final var x: Int, final private var y: Int, var z1: Int, private var z2: Int) { }
13+
14+
def f = new X(0).x += 1
15+
def main(args: Array[String]) {
16+
f
17+
val s = new X(0)
18+
s.x += 1
19+
println(s.x)
20+
21+
(classOf[X].getDeclaredFields map ("" + _)).sorted foreach println
22+
(classOf[Y].getDeclaredFields map ("" + _)).sorted foreach println
23+
}
24+
}

0 commit comments

Comments
 (0)