Skip to content

Commit 0c562db

Browse files
committed
Propagate the DEFAULTINIT flag to the underlying field
Fields initialized with `_` are excluded from initialization checks under `-Xcheckinit`. Since 5f86b1d, the compiler checks that flag on the field symbol instead of the getter. Unfortunately the flag was not actually copied to the field symbol, causing the init check to be added. Fixes scala/bug#10439, scala/bug#10437.
1 parent e12ac74 commit 0c562db

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/reflect/scala/reflect/internal/Flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class Flags extends ModifierFlags {
268268
* PRIVATE, LOCAL.
269269
*/
270270
final val FieldFlags =
271-
MUTABLE | CASEACCESSOR | PARAMACCESSOR | STATIC | FINAL | PRESUPER | LAZY
271+
MUTABLE | CASEACCESSOR | PARAMACCESSOR | STATIC | FINAL | PRESUPER | LAZY | DEFAULTINIT
272272

273273
/** Masks for getters and setters, where the flags are derived from those
274274
* on the field's modifiers. Both getters and setters get the ACCESSOR flag.

test/files/run/t10439.flags

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

test/files/run/t10439.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
private var s: String = _
3+
4+
def getS: String = {
5+
if (s == null) {
6+
s = ""
7+
}
8+
s
9+
}
10+
11+
def main(args: Array[String]): Unit = {
12+
assert(getS == "")
13+
}
14+
}

0 commit comments

Comments
 (0)