[FIR] Report VAL_REASSIGNMENT on assign to non-local vals

In this commit reporting on member properties in init section of class
  is not supported (see KT-55528)

^KT-55493 Fixed
This commit is contained in:
Dmitriy Novozhilov
2022-12-16 17:05:32 +02:00
committed by Space Team
parent e87a064cdd
commit 02e327277e
29 changed files with 321 additions and 49 deletions
@@ -116,8 +116,8 @@ class AnonymousInitializers(var a: String, val b: String) {
a = "30"
a = "s"
b = "3"
b = "tt" //repeat for b
<!VAL_REASSIGNMENT!>b<!> = "3"
<!VAL_REASSIGNMENT!>b<!> = "tt" //repeat for b
}
val i: Int
@@ -127,7 +127,7 @@ class AnonymousInitializers(var a: String, val b: String) {
init {
x = 11
z = 10
<!VAL_REASSIGNMENT!>z<!> = 10
}
val j: Int
@@ -135,7 +135,7 @@ class AnonymousInitializers(var a: String, val b: String) {
init {
i = 13
j = 34
<!VAL_REASSIGNMENT!>j<!> = 34
}
val k: String
@@ -228,13 +228,13 @@ class Outer() {
inner class Inner() {
init {
a++
<!VAL_REASSIGNMENT!>a<!>++
b++
}
}
fun foo() {
a++
<!VAL_REASSIGNMENT!>a<!>++
b++
}
}
@@ -271,8 +271,8 @@ fun foo() {
z = 3
}
fun foo() {
y = 10
z = 13
<!VAL_REASSIGNMENT!>y<!> = 10
<!VAL_REASSIGNMENT!>z<!> = 13
}
}
}
@@ -290,12 +290,12 @@ class TestObjectExpression() {
x = 1
}
fun inner1() {
y = 101
a = 231
<!VAL_REASSIGNMENT!>y<!> = 101
<!VAL_REASSIGNMENT!>a<!> = 231
}
fun inner2() {
y = 101
a = 231
<!VAL_REASSIGNMENT!>y<!> = 101
<!VAL_REASSIGNMENT!>a<!> = 231
}
}
}
@@ -311,7 +311,7 @@ object TestObjectDeclaration {
}
fun foo() {
y = 10
<!VAL_REASSIGNMENT!>y<!> = 10
val i: Int
if (1 < 3) {
i = 10
@@ -338,11 +338,11 @@ class M() {
}
fun test(m : M) {
m.x = 23
m.<!VAL_REASSIGNMENT!>x<!> = 23
m.y = 23
}
fun test1(m : M) {
m.x++
m.<!VAL_REASSIGNMENT!>x<!>++
m.y--
}
@@ -86,5 +86,5 @@ class My {
<!MUST_BE_INITIALIZED!>val top: Int<!>
fun init() {
top = 1
<!VAL_REASSIGNMENT!>top<!> = 1
}
@@ -8,8 +8,8 @@ fun foo(a: A) {
get() = 42
}
a.z = 23
o.y = 11 //Should be an error here
a.<!VAL_REASSIGNMENT!>z<!> = 23
o.<!VAL_REASSIGNMENT!>y<!> = 11 //Should be an error here
}
class A() {
@@ -0,0 +1,20 @@
//KT-897 Don't allow assignment to a property before it is defined
package kt897
class A() {
init {
<!INITIALIZATION_BEFORE_DECLARATION, VAL_REASSIGNMENT!>i<!> = 11
}
val i : Int? = null // must be an error
init {
<!INITIALIZATION_BEFORE_DECLARATION!>j<!> = 1
}
var j : Int = 2
init {
<!INITIALIZATION_BEFORE_DECLARATION!>k<!> = 3
}
val k : Int
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
//KT-897 Don't allow assignment to a property before it is defined
package kt897
@@ -6,9 +6,9 @@ class Outer {
outerProp // use of outerProp is ok because we're suppose that Outer instance should be initialized
this@Outer.outerProp
this@Outer.outerProp = "1"
outerProp = "2" // do not repeat the same diagnostic with this receiver of outer class
outer.outerProp = "3"
this@Outer.<!VAL_REASSIGNMENT!>outerProp<!> = "1"
<!VAL_REASSIGNMENT!>outerProp<!> = "2" // do not repeat the same diagnostic with this receiver of outer class
outer.<!VAL_REASSIGNMENT!>outerProp<!> = "3"
innerProp = "4" + inner.innerProp
this@Inner.innerProp = "5"