Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/variables/staticJavaFieldFromOtherModule.kt
T
Dmitry Savvinov 74fa6fc12c [k2, dfa] Smartcasts are not allowed on FirJavaField from other module
Handle case with FirField properly. Previously the code was returning
STABLE_VALUE in that case.

Note that in fact the changed 'when' branch expects only FirJavaField,
as FirFieldImpl should be handled by FirBackingFieldSymbol-check at
the beginning of the method. However, it is impossible to refer to
FirJavaField directly due to module visibility

Enumerate all cases more carefully via exhaustive 'when',
it's more readable and will prevent potential issues in future in case
more subclasses are added.

^KT-58279 Fixed
2024-01-31 09:53:45 +00:00

31 lines
729 B
Kotlin
Vendored

// FIR_IDENTICAL
// SKIP_TXT
// MODULE: lib
// FILE: J.java
public class J {
public static final Object staticFinalJava = "";
public static Object staticNonFinalJava = "";
}
// MODULE: app(lib)
fun isCast() {
if (J.staticFinalJava is String) {
<!SMARTCAST_IMPOSSIBLE!>J.staticFinalJava<!>.length
(J.staticFinalJava as String).length
}
if (J.staticNonFinalJava is String) {
<!SMARTCAST_IMPOSSIBLE!>J.staticNonFinalJava<!>.length
(J.staticFinalJava as String).length
}
}
fun asCast() {
J.staticFinalJava as String
<!SMARTCAST_IMPOSSIBLE!>J.staticFinalJava<!>.length
J.staticNonFinalJava as String
<!SMARTCAST_IMPOSSIBLE!>J.staticNonFinalJava<!>.length
}