diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index d9e60c1ffc9..ed85fb7acba 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -390,7 +390,7 @@ abstract class FirDataFlowAnalyzer( when (val operation = typeOperatorCall.operation) { FirOperation.IS, FirOperation.NOT_IS -> { val expressionVariable = variableStorage.createSyntheticVariable(typeOperatorCall) - val isNotNullCheck = type.nullability == ConeNullability.NOT_NULL + val isNotNullCheck = !type.canBeNull val isRegularIs = operation == FirOperation.IS if (operandVariable.isReal()) { val hasTypeInfo = operandVariable typeEq type diff --git a/compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt index cd7358e05ac..4a94cf70a71 100644 --- a/compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt @@ -1,6 +1,6 @@ // !LANGUAGE: +NewInference inline fun foo(x: T?, y: T): T { - if (x is S) return x + if (x is S) return x return y } diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt index 35f672f1bd2..0dfb36ce12f 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt @@ -67,6 +67,24 @@ fun kt4565_2(a: SomeClass?) { } } +inline fun kt45345(a: SomeClass?) { + if (a?.data is T) { + a.data + } +} + +inline fun kt45345_2(a: SomeClass?) { + if (a?.data is T) { + a.data + } +} + +inline fun kt45345_3(a: SomeClass?) { + if (a?.data is T) { + a.data + } +} + class A(val y: Int) fun kt7491_1() { diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.kt index 13f79d76f0d..c884bacb6f2 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.kt @@ -67,6 +67,24 @@ fun kt4565_2(a: SomeClass?) { } } +inline fun kt45345(a: SomeClass?) { + if (a?.data is T) { + a.data + } +} + +inline fun kt45345_2(a: SomeClass?) { + if (a?.data is T) { + a.data + } +} + +inline fun kt45345_3(a: SomeClass?) { + if (a?.data is T) { + a.data + } +} + class A(val y: Int) fun kt7491_1() { diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.txt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.txt index ca0619071bf..888f291b963 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.txt +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.txt @@ -10,6 +10,9 @@ public fun kt11313(/*0*/ arg: HttpExchange?): kotlin.Unit public fun kt1635(/*0*/ s: kotlin.String?): kotlin.Unit public fun kt2127(): kotlin.Unit public fun kt3356(/*0*/ s: kotlin.String?): kotlin.Int +public inline fun kt45345(/*0*/ a: SomeClass?): kotlin.Unit +public inline fun kt45345_2(/*0*/ a: SomeClass?): kotlin.Unit +public inline fun kt45345_3(/*0*/ a: SomeClass?): kotlin.Unit public fun kt4565_1(/*0*/ a: SomeClass?): kotlin.Unit public fun kt4565_2(/*0*/ a: SomeClass?): kotlin.Unit public fun kt6840_1(/*0*/ s: kotlin.String?): kotlin.Unit diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/type-contexts-and-scopes/inner-and-nested-type-contexts/p-1/pos/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/type-contexts-and-scopes/inner-and-nested-type-contexts/p-1/pos/1.1.fir.kt index d3f5851c91e..8f50f965e0d 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/type-system/type-contexts-and-scopes/inner-and-nested-type-contexts/p-1/pos/1.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/type-contexts-and-scopes/inner-and-nested-type-contexts/p-1/pos/1.1.fir.kt @@ -22,7 +22,7 @@ class Case1(val x: AT) { when (k) { is AT -> { - k checkType { check() } + k checkType { check() } } } } @@ -31,7 +31,7 @@ class Case1(val x: AT) { val k: AT = x!! if (k is AT) { - k checkType { check() } + k checkType { check() } } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt index 7aa1e2cb1fb..de3388e7195 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/23.fir.kt @@ -8,8 +8,8 @@ */ inline fun case_1(x: T) { if (x is K) { - x - x.equals(x) + x + x.equals(x) } } @@ -31,8 +31,8 @@ inline fun case_3() { var x: T? = 10 as T x = null if (x is K) { - x.equals(10) - x + x.equals(10) + x println(1) } } @@ -40,8 +40,8 @@ inline fun case_3() { // TESTCASE NUMBER: 4 inline fun case_4(x: T?) { if (x is K) { - x - x.equals(x) + x + x.equals(x) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/41.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/41.fir.kt index 838fdb7b345..930c7cabe0e 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/41.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/41.fir.kt @@ -6,13 +6,13 @@ inline fun case_1(x: Any?) { when (x) { is T -> { - x - x.equals(10) + x + x.equals(10) } else -> return } - x - x.equals(10) + x + x.equals(10) } // TESTCASE NUMBER: 2 @@ -23,13 +23,13 @@ inline fun case_2(x: Any?) { x.equals(10) } is T -> { - x - x.equals(10) + x + x.equals(10) } else -> return } - x - x.equals(10) + x + x.equals(10) } // TESTCASE NUMBER: 3 @@ -61,11 +61,11 @@ inline fun case_4(x: Any?) { // TESTCASE NUMBER: 5 inline fun case_5(x: Any?) { if (x is T) { - x - x.equals(10) + x + x.equals(10) } else return - x - x.equals(10) + x + x.equals(10) } // TESTCASE NUMBER: 6 @@ -81,9 +81,9 @@ inline fun case_7(x: Any?) { x x.equals(10) } else if (x is T) { - x - x.equals(10) + x + x.equals(10) } else return - x - x.equals(10) + x + x.equals(10) } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/22.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/22.fir.kt index 1ebedfb4d7c..55bad8b0f55 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/22.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/22.fir.kt @@ -118,7 +118,7 @@ fun case_11(x: Any?) { inline fun case_12(x: Any?) { if (x is T) { if (x is T is K) { - x + x } } } @@ -127,7 +127,7 @@ inline fun case_12(x: Any?) { inline fun case_13(x: Any?) { if (x is T) { if (x is K) { - x + x } } } @@ -136,7 +136,7 @@ inline fun case_13(x: Any?) { inline fun case_14(x: Any?) { if (x is T) { if (x !is T) { - x + x } } } @@ -145,7 +145,7 @@ inline fun case_14(x: Any?) { inline fun case_15(x: Any?) { if (x !is T) { if (x is T) { - x + x } } }