[FIR] Properties defined in a do-while may not always be initialized
Local properties defined within the body of a do-while loop can be used in the condition of the loop. However, use of a `continue` may mean the property isn't always initialized, even if it is initialized when it is defined. So while a local property may be within scope and has an initializer, this doesn't always mean that the property is initialized. As such, properties that are defined within a do-while loop and also used in the condition of the same do-while loop should be tracked. Then, these properties should still be checked for proper initialization even if they have an initializer. ^KT-64872 Fixed
This commit is contained in:
-6
@@ -1,6 +0,0 @@
|
||||
fun test(cond1: Boolean) {
|
||||
do {
|
||||
if (cond1) continue
|
||||
val cond2 = false
|
||||
} while (cond2) // cond2 may be not defined here
|
||||
}
|
||||
+37
-1
@@ -1,6 +1,42 @@
|
||||
fun test(cond1: Boolean) {
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
|
||||
fun test1(cond1: Boolean) {
|
||||
do {
|
||||
if (cond1) continue
|
||||
val cond2 = false
|
||||
} while (<!UNINITIALIZED_VARIABLE!>cond2<!>) // cond2 may be not defined here
|
||||
}
|
||||
|
||||
fun test2(cond1: Boolean, cond3: Boolean) {
|
||||
do {
|
||||
if (cond1) continue
|
||||
val cond2 = false
|
||||
} while (
|
||||
run {
|
||||
do {
|
||||
if (cond3) continue
|
||||
val cond4 = false
|
||||
} while (<!UNINITIALIZED_VARIABLE!>cond4<!>) // cond4 may be not defined here
|
||||
|
||||
<!UNINITIALIZED_VARIABLE!>cond2<!> // cond2 may be not defined here
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fun test3(cond1: Boolean, cond3: Boolean) {
|
||||
do {
|
||||
if (cond1) continue
|
||||
val cond2 = false
|
||||
} while (
|
||||
run {
|
||||
do {
|
||||
if (cond3) continue
|
||||
val cond4 = false
|
||||
} while (<!UNINITIALIZED_VARIABLE!>cond2<!> && <!UNINITIALIZED_VARIABLE!>cond4<!>) // cond2 and cond4 may be not defined here
|
||||
|
||||
cond3
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ cond1: kotlin.Boolean): kotlin.Unit
|
||||
Reference in New Issue
Block a user