[FIR] Prohibit is-checks and casts for unrelated nullable types
This decision was made after a discussion in Slack.
This commit is contained in:
committed by
Space Team
parent
a4c33ee785
commit
405852980d
+4
-1
@@ -75,7 +75,10 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker(MppCheckerKind.Commo
|
|||||||
|
|
||||||
return when {
|
return when {
|
||||||
isRefinementUseless(context, l.directType.upperBoundIfFlexible(), r.directType, expression) -> useless
|
isRefinementUseless(context, l.directType.upperBoundIfFlexible(), r.directType, expression) -> useless
|
||||||
oneIsNotNull && shouldReportAsPerRules1(l, r, context) -> impossible
|
shouldReportAsPerRules1(l, r, context) -> when {
|
||||||
|
oneIsNotNull -> impossible
|
||||||
|
else -> useless
|
||||||
|
}
|
||||||
isCastErased(l.directType, r.directType, context) -> Applicability.CAST_ERASED
|
isCastErased(l.directType, r.directType, context) -> Applicability.CAST_ERASED
|
||||||
else -> Applicability.APPLICABLE
|
else -> Applicability.APPLICABLE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// From KT-13324: always succeeds
|
||||||
|
val x = null as String?
|
||||||
|
// From KT-260: sometimes succeeds
|
||||||
|
fun foo(a: String?): Int? {
|
||||||
|
val c = a <!USELESS_CAST!>as? Int?<!>
|
||||||
|
return c
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
// FIR_IDENTICAL
|
|
||||||
// From KT-13324: always succeeds
|
// From KT-13324: always succeeds
|
||||||
val x = null as String?
|
val x = null as String?
|
||||||
// From KT-260: sometimes succeeds
|
// From KT-260: sometimes succeeds
|
||||||
|
|||||||
Reference in New Issue
Block a user