99e51f6940
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
68 lines
1.0 KiB
Kotlin
Vendored
68 lines
1.0 KiB
Kotlin
Vendored
// Tests for KT-13597 (val assignment inside local object in constructor)
|
|
|
|
class Test {
|
|
val a: String
|
|
|
|
init {
|
|
val t = object {
|
|
fun some() {
|
|
// See KT-13597
|
|
<!VAL_REASSIGNMENT!>a<!> = "12"
|
|
}
|
|
}
|
|
|
|
a = "2"
|
|
t.some()
|
|
}
|
|
}
|
|
|
|
class Test2 {
|
|
init {
|
|
val t = object {
|
|
fun some() {
|
|
<!VAL_REASSIGNMENT!>a<!> = "12"
|
|
}
|
|
}
|
|
|
|
<!INITIALIZATION_BEFORE_DECLARATION!>a<!> = "2"
|
|
t.some()
|
|
}
|
|
|
|
val a: String
|
|
}
|
|
|
|
// Tests for KT-14381 (val assignment inside lambda in constructor)
|
|
|
|
fun <T> exec(f: () -> T): T = f()
|
|
|
|
class Test4 {
|
|
val a: String
|
|
|
|
init {
|
|
exec {
|
|
// See KT-14381
|
|
<!CAPTURED_MEMBER_VAL_INITIALIZATION!>a<!> = "12"
|
|
}
|
|
a = "34"
|
|
}
|
|
}
|
|
|
|
// Additional tests to prevent something broken
|
|
|
|
class Test5 {
|
|
|
|
val y: Int
|
|
|
|
val z: String
|
|
|
|
init {
|
|
val x: String
|
|
x = ""
|
|
z = x
|
|
}
|
|
|
|
constructor(y: Int) {
|
|
this.y = y
|
|
}
|
|
}
|