[FIR] Support boolean elvis bound smartcasts
#KT-44511 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
2b088f1147
commit
9724d81a49
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
FILE: booleanElvisBoundSmartcast.kt
|
||||
public final class A : R|kotlin/Any| {
|
||||
public constructor(b: R|kotlin/Boolean|): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val b: R|kotlin/Boolean| = R|<local>/b|
|
||||
public get(): R|kotlin/Boolean|
|
||||
|
||||
public final fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test_1(a: R|A?|): R|kotlin/Unit| {
|
||||
when () {
|
||||
R|<local>/a|?.{ $subj$.R|/A.b| } ?: Boolean(false) -> {
|
||||
R|<local>/a|.R|/A.foo|()
|
||||
}
|
||||
else -> {
|
||||
R|<local>/a|.<Inapplicable(INAPPLICABLE_WRONG_RECEIVER): /A.foo>#()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test_2(a: R|A?|): R|kotlin/Unit| {
|
||||
when () {
|
||||
R|<local>/a|?.{ $subj$.R|/A.b| } ?: Boolean(true) -> {
|
||||
R|<local>/a|.<Inapplicable(INAPPLICABLE_WRONG_RECEIVER): /A.foo>#()
|
||||
}
|
||||
else -> {
|
||||
R|<local>/a|.R|/A.foo|()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: +BooleanElvisBoundSmartCasts
|
||||
// ISSUE: KT-44511, also relates to KT-8492 and KT-26357
|
||||
|
||||
class A(val b: Boolean) {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun test_1(a: A?) {
|
||||
if (a?.b ?: false) {
|
||||
a.foo() // OK
|
||||
} else {
|
||||
a<!UNSAFE_CALL!>.<!>foo() // Error
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2(a: A?) {
|
||||
if (a?.b ?: true) {
|
||||
a<!UNSAFE_CALL!>.<!>foo() // Error
|
||||
} else {
|
||||
a.foo() // OK
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user