Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolveWithStdlib/initialization/fromLocalMembers.kt
T
pyos 99e51f6940 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
2023-01-26 13:12:13 +00:00

47 lines
702 B
Kotlin
Vendored

fun test1() {
val x: Int
fun func() {
<!CAPTURED_VAL_INITIALIZATION!>x<!> = 0
}
println(<!UNINITIALIZED_VARIABLE!>x<!>)
}
fun test2() {
val x: Int
val y: Int
object {
init {
x = 0
}
fun localFunc() {
<!CAPTURED_VAL_INITIALIZATION!>y<!> = 0
}
}
println(x)
println(x)
}
fun test3() {
val x: Int
val y: Int
class A {
init {
<!CAPTURED_VAL_INITIALIZATION!>x<!> = 0
}
fun localFunc() {
<!CAPTURED_VAL_INITIALIZATION!>y<!> = 0
}
}
println(<!UNINITIALIZED_VARIABLE!>x<!>)
println(<!UNINITIALIZED_VARIABLE!>x<!>)
}