FIR: check assignments and references to members in constructors
I.e. emit VAL_REASSIGNMENT on repeated assignments to `this.something`, UNINITIALIZED_VARIABLE on reads of it before any assignment if there is no initializer, and CAPTURED_MEMBER_VAL_INITIALIZATION on assignments inside non-called-in-place functions and named classes. ^KT-55528 Fixed
This commit is contained in:
Vendored
+2
-2
@@ -134,7 +134,7 @@ class AnonymousInitializers(var a: String, val b: String) {
|
||||
get() = 20
|
||||
|
||||
init {
|
||||
i = 13
|
||||
<!VAL_REASSIGNMENT!>i<!> = 13
|
||||
<!VAL_REASSIGNMENT!>j<!> = 34
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ class AnonymousInitializers(var a: String, val b: String) {
|
||||
val n: Int
|
||||
|
||||
init {
|
||||
while (n == 0) {
|
||||
while (<!UNINITIALIZED_VARIABLE!>n<!> == 0) {
|
||||
}
|
||||
n = 10
|
||||
while (n == 0) {
|
||||
|
||||
Vendored
+3
-3
@@ -7,7 +7,7 @@ class Test {
|
||||
val t = object {
|
||||
fun some() {
|
||||
// See KT-13597
|
||||
a = "12"
|
||||
<!VAL_REASSIGNMENT!>a<!> = "12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Test2 {
|
||||
init {
|
||||
val t = object {
|
||||
fun some() {
|
||||
a = "12"
|
||||
<!VAL_REASSIGNMENT!>a<!> = "12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Test4 {
|
||||
init {
|
||||
exec {
|
||||
// See KT-14381
|
||||
a = "12"
|
||||
<!CAPTURED_MEMBER_VAL_INITIALIZATION!>a<!> = "12"
|
||||
}
|
||||
a = "34"
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ fun gav() {
|
||||
class B {
|
||||
init {
|
||||
// Error! See KT-10445
|
||||
x = ""
|
||||
<!CAPTURED_VAL_INITIALIZATION!>x<!> = ""
|
||||
}
|
||||
}
|
||||
// Error! See KT-10042
|
||||
@@ -36,7 +36,7 @@ fun gav() {
|
||||
class C(val s: String) {
|
||||
constructor(): this("") {
|
||||
// Error!
|
||||
y = s
|
||||
<!CAPTURED_VAL_INITIALIZATION!>y<!> = s
|
||||
}
|
||||
}
|
||||
<!UNINITIALIZED_VARIABLE!>y<!>.length
|
||||
@@ -77,7 +77,7 @@ class My {
|
||||
class Your {
|
||||
init {
|
||||
// Error! See KT-10445
|
||||
x = ""
|
||||
<!CAPTURED_VAL_INITIALIZATION!>x<!> = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,9 +10,9 @@ class Test {
|
||||
|
||||
run {
|
||||
// Not sure do we need diagnostic also here
|
||||
this@Test.str = "B"
|
||||
this@Test.<!VAL_REASSIGNMENT!>str<!> = "B"
|
||||
}
|
||||
|
||||
str = "C"
|
||||
<!VAL_REASSIGNMENT!>str<!> = "C"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,9 +10,9 @@ class Test {
|
||||
|
||||
run {
|
||||
// Not sure do we need diagnostic also here
|
||||
this@Test.str = "B"
|
||||
this@Test.<!VAL_REASSIGNMENT!>str<!> = "B"
|
||||
}
|
||||
|
||||
str = "C"
|
||||
<!VAL_REASSIGNMENT!>str<!> = "C"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -3,9 +3,9 @@ class A(val next: A? = null) {
|
||||
init {
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "a"
|
||||
x = "b"
|
||||
this.x = "c"
|
||||
x = "d" // don't repeat the same diagnostic again with this receiver
|
||||
this.x = "e"
|
||||
this.<!VAL_REASSIGNMENT!>x<!> = "c"
|
||||
<!VAL_REASSIGNMENT!>x<!> = "d" // don't repeat the same diagnostic again with this receiver
|
||||
this.<!VAL_REASSIGNMENT!>x<!> = "e"
|
||||
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "f"
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -11,9 +11,9 @@ class Outer {
|
||||
outer.<!VAL_REASSIGNMENT!>outerProp<!> = "3"
|
||||
|
||||
innerProp = "4" + inner.innerProp
|
||||
this@Inner.innerProp = "5"
|
||||
innerProp = "6" // do not repeat the same diagnostic with this receiver
|
||||
this@Inner.innerProp = "7"
|
||||
this@Inner.<!VAL_REASSIGNMENT!>innerProp<!> = "5"
|
||||
<!VAL_REASSIGNMENT!>innerProp<!> = "6" // do not repeat the same diagnostic with this receiver
|
||||
this@Inner.<!VAL_REASSIGNMENT!>innerProp<!> = "7"
|
||||
|
||||
inner.<!VAL_REASSIGNMENT!>innerProp<!> = "8"
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,9 +3,9 @@ class A(val next: A? = null) {
|
||||
init {
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "a"
|
||||
this@A.x = "b"
|
||||
this.x = "c"
|
||||
x = "d" // don't repeat the same diagnostic again with this receiver
|
||||
this@A.x = "e"
|
||||
this.<!VAL_REASSIGNMENT!>x<!> = "c"
|
||||
<!VAL_REASSIGNMENT!>x<!> = "d" // don't repeat the same diagnostic again with this receiver
|
||||
this@A.<!VAL_REASSIGNMENT!>x<!> = "e"
|
||||
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "f"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user