Files
kotlin-fork/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalClass.fir.kt
T
Dmitriy Novozhilov 02e327277e [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
2022-12-20 08:12:09 +00:00

91 lines
1.4 KiB
Kotlin
Vendored

// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
fun foo() {
var x: String
class A {
init {
x = ""
}
}
// Error! See KT-10042
<!UNINITIALIZED_VARIABLE!>x<!>.length
}
fun bar() {
var x: String
object: Any() {
init {
x = ""
}
}
// Ok
x.length
}
fun gav() {
val x: String
class B {
init {
// Error! See KT-10445
x = ""
}
}
// Error! See KT-10042
<!UNINITIALIZED_VARIABLE!>x<!>.length
val y: String
class C(val s: String) {
constructor(): this("") {
// Error!
y = s
}
}
<!UNINITIALIZED_VARIABLE!>y<!>.length
}
open class Gau(val s: String)
fun gau() {
val x: String
object: Any() {
init {
// Ok
x = ""
}
}
// Ok
x.length
val y: String
fun local() {
object: Any() {
init {
// Error!
<!CAPTURED_VAL_INITIALIZATION!>y<!> = ""
}
}
}
val z: String
object: Gau(if (true) {
z = ""
z
}
else "") {}
}
class My {
init {
val x: String
class Your {
init {
// Error! See KT-10445
x = ""
}
}
}
}
<!MUST_BE_INITIALIZED!>val top: Int<!>
fun init() {
<!VAL_REASSIGNMENT!>top<!> = 1
}