Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonLocalProperty_initializedProperties.kt
Brian Norman 7db551c452 [FIR] Property accessors are not part of class initialization
When checking for class val property reassignment diagnostic, property
initializers should be treated as part of the class initialization.
However, property accessors should not. Previously, only the property
itself was checked for both of these situations and resulted in not
reporting diagnostic within property accessors.

#KT-59744 Fixed
2023-08-22 13:28:36 +00:00

70 lines
1.7 KiB
Kotlin
Vendored

// ISSUE: KT-55493, KT-59744
// WITH_STDLIB
val z: String = "ok"
val Some.y: String
get() = "ok"
class Some {
val x: String = "ok"
init {
<!VAL_REASSIGNMENT!>x<!> = "error"
<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
}
val a: String = run {
<!VAL_REASSIGNMENT!>x<!> = "error"
<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
"hello"
}
var b: String = "hello"
get() {
<!VAL_REASSIGNMENT!>x<!> = "error"
<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
return field
}
set(value) {
<!VAL_REASSIGNMENT!>x<!> = value
<!VAL_REASSIGNMENT!>y<!> = value
<!VAL_REASSIGNMENT!>z<!> = value
field = value
}
var c: String
get() {
<!VAL_REASSIGNMENT!>x<!> = "error"
<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
return "hello"
}
set(value) {
<!VAL_REASSIGNMENT!>x<!> = value
<!VAL_REASSIGNMENT!>y<!> = value
<!VAL_REASSIGNMENT!>z<!> = value
}
fun test_1() {
<!VAL_REASSIGNMENT!>x<!> = "error"
<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
}
}
fun Some.test_2() {
<!VAL_REASSIGNMENT!>x<!> = "error"
<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
}
fun test_3(some: Some) {
some.<!VAL_REASSIGNMENT!>x<!> = "error"
some.<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
}