diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt index c80ce771b46..ebba871b1d5 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt @@ -75,7 +75,10 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker(MppCheckerKind.Commo return when { 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 else -> Applicability.APPLICABLE } diff --git a/compiler/testData/diagnostics/tests/cast/NullableToNullable.fir.kt b/compiler/testData/diagnostics/tests/cast/NullableToNullable.fir.kt new file mode 100644 index 00000000000..5042aea4ca0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/NullableToNullable.fir.kt @@ -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 as? Int? + return c +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt b/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt index ef045bf58f8..cd76ae9a3c2 100644 --- a/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt +++ b/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // From KT-13324: always succeeds val x = null as String? // From KT-260: sometimes succeeds