[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
This commit is contained in:
Dmitry Savvinov
2024-01-17 15:16:08 +01:00
committed by Space Team
parent 6661a66fc3
commit 74fa6fc12c
2 changed files with 37 additions and 21 deletions
@@ -11,8 +11,8 @@ public class J {
// MODULE: app(lib)
fun isCast() {
if (J.staticFinalJava is String) {
J.staticFinalJava.length
(J.staticFinalJava <!USELESS_CAST!>as String<!>).length
<!SMARTCAST_IMPOSSIBLE!>J.staticFinalJava<!>.length
(J.staticFinalJava as String).length
}
if (J.staticNonFinalJava is String) {
@@ -23,7 +23,7 @@ fun isCast() {
fun asCast() {
J.staticFinalJava as String
J.staticFinalJava.length
<!SMARTCAST_IMPOSSIBLE!>J.staticFinalJava<!>.length
J.staticNonFinalJava as String
<!SMARTCAST_IMPOSSIBLE!>J.staticNonFinalJava<!>.length