Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcasts.kt
T
Mikhail Glukhikh 53d6ac24e5 Switch kotlin version to 1.7
* Change 1.6 to 1.7 constants
* Fix SAFE_CALL_WILL_CHANGE_NULLABILITY for testData
* Change EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_WARNING to EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR
* Change NON_EXHAUSTIVE_WHEN_STATEMENT to NO_ELSE_IN_WHEN
* Fix testData for SafeCallsAreAlwaysNullable
* Change T -> T & Any in test dumps
* Change INVALID_CHARACTERS_NATIVE_WARNING -> INVALID_CHARACTERS_NATIVE_ERROR
* TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_WARNING -> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR
2022-02-25 11:46:27 +00:00

79 lines
1.2 KiB
Kotlin
Vendored

// !DUMP_CFG
interface A {
fun foo()
}
interface B {
fun bar()
}
fun test_1(x: Any) {
val y = x
if (x is A) {
x.foo()
y.foo()
}
}
fun test_2(x: Any) {
val y = x
if (y is A) {
x.foo()
y.foo()
}
}
fun test_3(x: Any, y: Any) {
var z = x
if (x is A) {
z.foo()
}
z = y
if (y is B) {
z.<!UNRESOLVED_REFERENCE!>foo<!>()
z.bar()
}
}
fun test_4(y: Any) {
var x: Any = 1
x as Int
x.inc()
x = y
x.<!UNRESOLVED_REFERENCE!>inc<!>()
if (y is A) {
x.foo()
y.foo()
}
}
class D(val any: Any?)
fun Any.baz() {}
fun test_5(d: D) {
// Elvis operator is converted into == function call
val a = d.any ?: return
a.baz() // should be OK
d.any.baz() // should be OK
a as A
a.foo() // should be OK
}
fun test_6(d1: D) {
val a = d1.any
a as A
a.foo() // should be OK
d1.any.foo() // should be OK
d1.any.baz() // should be OK
}
fun test_7(d1: D, d2: D) {
val a = d1<!UNNECESSARY_SAFE_CALL!>?.<!>any
val b = d2<!UNNECESSARY_SAFE_CALL!>?.<!>any
a as A
a.foo() // should be OK
b as B
b.bar() // should be OK
}