[K2] Prohibit smart casts for 'expect' properties

^KT-61340
This commit is contained in:
Anastasia.Nekrasova
2023-09-19 19:03:15 +03:00
committed by Space Team
parent e4ea733482
commit e3bab4a7da
9 changed files with 150 additions and 0 deletions
@@ -0,0 +1,25 @@
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
// MODULE: m1-common
// FILE: common.kt
expect val foo: Any
expect class Bar() {
val bus: Any
}
fun common() {
if (foo is String) <!SMARTCAST_IMPOSSIBLE!>foo<!>.length
val bar = Bar()
if (bar.bus is String) <!SMARTCAST_IMPOSSIBLE!>bar.bus<!>.length
}
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual val foo: Any = 2
actual class Bar actual constructor() {
actual val bus: Any
get() = "bus"
}
@@ -0,0 +1,25 @@
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
// MODULE: m1-common
// FILE: common.kt
expect val foo: Any
expect class Bar() {
val bus: Any
}
fun common() {
if (foo is String) foo.length
val bar = Bar()
if (bar.bus is String) <!SMARTCAST_IMPOSSIBLE{JVM}!>bar.bus<!>.length
}
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual val foo: Any = 2
actual class Bar actual constructor() {
actual val bus: Any
get() = "bus"
}
@@ -0,0 +1,26 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
// MODULE: m1-common
// FILE: common.kt
expect val foo: Any
expect class Bar() {
val bus: Any
}
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual val foo: Any = 2
actual class Bar actual constructor() {
actual val bus: Any
get() = "bus"
}
fun platform() {
if (foo is String) foo.length
val bar = Bar()
if (bar.bus is String) <!SMARTCAST_IMPOSSIBLE!>bar.bus<!>.length
}