[FIR] Comparison to String implies smart cast to String
When the left-hand side of an equality comparison is known to be a String, and the equality condition resolves to true, then the right-hand side can be smart-cast to a String as well. This was working for String expressions on the left-hand side but not for String constants. ^KT-57513 Fixed
This commit is contained in:
@@ -8,8 +8,8 @@ import checkSubtype
|
||||
fun main(args : Array<String>) {
|
||||
val x = checkSubtype<Any>(args[0])
|
||||
if(x is <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.CharSequence<!>) {
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!>) x.<!FUNCTION_CALL_EXPECTED!>length<!> else x.length() // OK
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!> || <!EQUALITY_NOT_APPLICABLE_WARNING!>"b" == x<!>) x.<!FUNCTION_CALL_EXPECTED!>length<!> else x.length() // <– THEN ERROR
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!> && <!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!>) x.<!FUNCTION_CALL_EXPECTED!>length<!> else x.length() // <– ELSE ERROR
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!>) x.length else x.length() // OK
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!> || <!EQUALITY_NOT_APPLICABLE_WARNING!>"b" == x<!>) x.length else x.length() // <– THEN ERROR
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>"a" == x<!> && "a" == x) x.length else x.length() // <– ELSE ERROR
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user