FIR CFG: add more KT-44512 related tests
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
// !DUMP_CFG
|
||||
|
||||
fun <T> foo(x: T?, i: Int, y: T) {}
|
||||
|
||||
fun <T> id(x: T): T = x
|
||||
|
||||
fun <T> n(): T? = null
|
||||
|
||||
fun someCompletedCall(arg: Int) = arg
|
||||
|
||||
fun test1(x: String?) {
|
||||
foo(
|
||||
id(run { x as String; n() }),
|
||||
1,
|
||||
run { x<!UNSAFE_CALL!>.<!>length; 123 } // Bad (resolution order undefined)
|
||||
)
|
||||
x.length // OK (x as String unconditional)
|
||||
}
|
||||
|
||||
fun test2(x: String?) {
|
||||
foo(
|
||||
id(run { x as String; n() }),
|
||||
someCompletedCall(1),
|
||||
run { x.length; 123 } // Bad (resolution order undefined)
|
||||
)
|
||||
x.length // OK (x as String unconditional)
|
||||
}
|
||||
|
||||
fun test3(x: String?) {
|
||||
foo(
|
||||
id(run { x as String; n() }),
|
||||
if (true) 1 else 2,
|
||||
run { x<!UNSAFE_CALL!>.<!>length; 123 } // Bad (resolution order undefined)
|
||||
)
|
||||
x<!UNSAFE_CALL!>.<!>length // OK (x as String unconditional)
|
||||
}
|
||||
|
||||
fun test4(x: String?) {
|
||||
var p = x
|
||||
if (p != null) {
|
||||
foo(
|
||||
id(if (true) run { p = null; n() } else run { n() }),
|
||||
1,
|
||||
run { p.length; 123 } // Bad (p = null possible)
|
||||
)
|
||||
p.length // Bad (p = null possible)
|
||||
}
|
||||
}
|
||||
|
||||
fun test5(x: String?, y: String?) {
|
||||
foo(
|
||||
y?.let { x as String; n() },
|
||||
1,
|
||||
run { "" }
|
||||
)
|
||||
x.length // Bad (x as String conditional)
|
||||
}
|
||||
|
||||
fun test6(x: String?) {
|
||||
foo(
|
||||
id(if (true) run { x as String; n() } else run { x as String; n() }),
|
||||
1,
|
||||
run { x<!UNSAFE_CALL!>.<!>length; 123 } // Bad (resolution order undefined)
|
||||
)
|
||||
x<!UNSAFE_CALL!>.<!>length // OK (x as String in both branches)
|
||||
}
|
||||
|
||||
fun test7(x: String?) {
|
||||
var p = x
|
||||
if (p != null) {
|
||||
foo(
|
||||
id(run { p = null; n() }),
|
||||
1,
|
||||
run { p.length; 123 } // Bad (p = null)
|
||||
)
|
||||
p.length // Bad (p = null)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user