From 8d04ab3142606e9905cea25a00fcd07eb5542da7 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 19 Apr 2023 10:27:17 +0300 Subject: [PATCH] [FIR] Ignore nullability in the definition of "identity-less" The definition of a "builtin" already ignores nullability. `Int? === String?` must trigger a diagnostic by design. --- .../resolve/smartcasts/nullability.kt | 4 +- .../FirEqualityCompatibilityChecker.kt | 21 +- .../tests/BinaryCallsOnNullableValues.fir.kt | 4 +- .../stubTypes/memberScope.fir.kt | 30 +-- ...identityComparisonWithInlineClasses.fir.kt | 6 +- .../identityComparisonWithValueClasses.fir.kt | 6 +- .../equalityCompatibilityCommonCases.fir.kt | 8 +- .../diagnostics/notLinked/dfa/neg/1.fir.kt | 2 +- .../diagnostics/notLinked/dfa/neg/15.fir.kt | 2 +- .../diagnostics/notLinked/dfa/pos/1.fir.kt | 186 +++++++++--------- .../diagnostics/notLinked/dfa/pos/16.fir.kt | 6 +- .../diagnostics/notLinked/dfa/pos/17.fir.kt | 2 +- .../diagnostics/notLinked/dfa/pos/18.fir.kt | 6 +- .../diagnostics/notLinked/dfa/pos/28.fir.kt | 28 +-- .../diagnostics/notLinked/dfa/pos/3.fir.kt | 4 +- .../diagnostics/notLinked/dfa/pos/39.fir.kt | 4 +- .../diagnostics/notLinked/dfa/pos/5.fir.kt | 2 +- .../diagnostics/notLinked/dfa/pos/6.fir.kt | 20 +- .../diagnostics/notLinked/dfa/pos/7.fir.kt | 14 +- 19 files changed, 179 insertions(+), 176 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.kt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.kt index 9736e45d421..cb3dda18b2d 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.kt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.kt @@ -123,7 +123,7 @@ fun test_10(a: Int?, b: Int?) { } b.inc() - if (a === b) { + if (a === b) { b.inc() } b.inc() @@ -133,7 +133,7 @@ fun test_10(a: Int?, b: Int?) { } b.inc() - if (b === a) { + if (b === a) { b.inc() } b.inc() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt index 87f822833ce..fb157705367 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt @@ -121,15 +121,15 @@ object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker() { // we only need to check if one is related // to the other - fun TypeInfo.isSubtypeOf(other: TypeInfo) = - notNullType.isSubtypeOf(other.notNullType, context.session) - return when { l.type.isNothingOrNullableNothing || r.type.isNothingOrNullableNothing -> false - else -> !l.isSubtypeOf(r) && !r.isSubtypeOf(l) + else -> !l.isSubtypeOf(r, context) && !r.isSubtypeOf(l, context) } } + private fun TypeInfo.isSubtypeOf(other: TypeInfo, context: CheckerContext) = + notNullType.isSubtypeOf(other.notNullType, context.session) + private enum class Applicability { APPLICABLE, GENERALLY_INAPPLICABLE, @@ -153,12 +153,13 @@ object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker() { forceWarning: Boolean, context: CheckerContext, ): KtDiagnosticFactory2 { - val areBothPrimitives = l.isPrimitive && r.isPrimitive + val areBothPrimitives = l.isNotNullPrimitive && r.isNotNullPrimitive val areSameTypes = l.type.classId == r.type.classId val shouldProperlyReportError = context.languageVersionSettings.supportsFeature(LanguageFeature.ReportErrorsForComparisonOperators) // In this case K1 reports nothing - val shouldRelaxDiagnostic = (l.type.isNullableNothing || r.type.isNullableNothing) && !shouldProperlyReportError + val shouldRelaxDiagnostic = (l.isPrimitive || r.isPrimitive) && (l.isSubtypeOf(r, context) || r.isSubtypeOf(l, context)) + && !shouldProperlyReportError return when { // See: KT-28252 @@ -174,7 +175,7 @@ object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker() { isPrimitiveWithNonPrimitiveSupertype(l, r, session) || isPrimitiveWithNonPrimitiveSupertype(r, l, session) private fun isPrimitiveWithNonPrimitiveSupertype(l: TypeInfo, r: TypeInfo, session: FirSession) = - l.isPrimitive && !r.isPrimitive && l.type.isSubtypeOf(r.type, session) + l.isNotNullPrimitive && !r.isNotNullPrimitive && l.type.isSubtypeOf(r.type, session) private fun getSourceLessInapplicabilityDiagnostic(forceWarning: Boolean) = when { forceWarning -> FirErrors.INCOMPATIBLE_TYPES_WARNING @@ -298,7 +299,9 @@ private val TypeInfo.enforcesEmptyIntersection get() = isFinalClass && !isEnumCl private val TypeInfo.isNullableEnum get() = isEnumClass && type.isNullable -private val TypeInfo.isIdentityLess get() = isPrimitive || !type.isNullable && isValueClass +private val TypeInfo.isIdentityLess get() = isPrimitive || isValueClass + +private val TypeInfo.isNotNullPrimitive get() = isPrimitive && !type.isNullable private val FirClassSymbol<*>.isFinalClass get() = isClass && isFinal @@ -315,7 +318,7 @@ private fun ConeKotlinType.toTypeInfo(session: FirSession): TypeInfo { type, notNullType, isFinalClass = bounds.any { it.toClassSymbol(session)?.isFinalClass == true }, isEnumClass = bounds.any { it.toClassSymbol(session)?.isEnumClass == true }, - isPrimitive = bounds.any { it.isPrimitive }, + isPrimitive = bounds.any { it.isPrimitiveOrNullablePrimitive }, isBuiltin = bounds.any { it.toClassSymbol(session)?.isBuiltin == true }, isValueClass = bounds.any { it.toClassSymbol(session)?.isInline == true }, isLiterallyTypeParameter = this.lowerBoundIfFlexible() is ConeTypeParameterType, diff --git a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt index 02449200689..86a9a5574a3 100644 --- a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt +++ b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt @@ -15,8 +15,8 @@ fun f(): Unit { A() == 1 - x === "1" - x !== "1" + x === "1" + x !== "1" x === 1 x !== 1 diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt index 2eea7892597..885e40cb4c3 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt @@ -54,7 +54,7 @@ fun test() { x?.equals(1) if (get() == null) {} - if (get() === null) {} + if (get() === null) {} if (x != null) { x?.hashCode() @@ -113,7 +113,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.hashCode() } @@ -123,7 +123,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.equals("") } @@ -133,7 +133,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.toString("") } @@ -143,7 +143,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.test() } @@ -170,7 +170,7 @@ fun test() { x?.equals(1) if (get() == null) {} - if (get() === null) {} + if (get() === null) {} if (x == null) { x?.hashCode() @@ -188,19 +188,19 @@ fun test() { x.test2() } - if (x === null) { + if (x === null) { x?.hashCode() } - if (x === null) { + if (x === null) { x?.equals(1) } - if (x === null) { + if (x === null) { x?.test2() } - if (x === null) { + if (x === null) { x.test2() } @@ -247,7 +247,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.equals("") } @@ -257,7 +257,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.hashCode() } "" @@ -266,7 +266,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.toString() } "" @@ -275,7 +275,7 @@ fun test() { emit(1) emit(null) val x = get() - if (x === null) { + if (x === null) { x.test() } "" @@ -300,7 +300,7 @@ fun test() { x?.equals(1) if (get() == null) {} - if (get() === null) {} + if (get() === null) {} if (x == null) { x?.hashCode() diff --git a/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt index 09fdf8a41ba..ad46066722a 100644 --- a/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt @@ -9,7 +9,7 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val a2 = f1 === f1 val a3 = f1 === b1 || f1 !== b1 - val c1 = fn1 === fn2 || fn1 !== fn2 + val c1 = fn1 === fn2 || fn1 !== fn2 val c2 = f1 === fn1 || f1 !== fn1 val c3 = b1 === fn1 || b1 !== fn1 @@ -17,6 +17,6 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val d1 = any === f1 || any !== f1 val d2 = f1 === any || f1 !== any - val d3 = any === fn1 || any !== fn1 - val d4 = fn1 === any || fn1 !== any + val d3 = any === fn1 || any !== fn1 + val d4 = fn1 === any || fn1 !== any } diff --git a/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt b/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt index dafcbba02e3..62f36836c62 100644 --- a/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt @@ -17,7 +17,7 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val a2 = f1 === f1 val a3 = f1 === b1 || f1 !== b1 - val c1 = fn1 === fn2 || fn1 !== fn2 + val c1 = fn1 === fn2 || fn1 !== fn2 val c2 = f1 === fn1 || f1 !== fn1 val c3 = b1 === fn1 || b1 !== fn1 @@ -25,6 +25,6 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val d1 = any === f1 || any !== f1 val d2 = f1 === any || f1 !== any - val d3 = any === fn1 || any !== fn1 - val d4 = fn1 === any || fn1 !== any + val d3 = any === fn1 || any !== fn1 + val d4 = fn1 === any || fn1 !== any } diff --git a/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt index 603e4a09686..f817c853084 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt @@ -75,24 +75,24 @@ fun incompatibleEnumComparisonSmartCast(c: Any?, e: Any?) { fun incompatibleIdentityRegardlessNullability(a: Int?, b: String?) { a == b - a === b + a === b } fun incompatibleIdentityRegardlessNullabilitySmartCast(a: Any?, b: Any?) { if (a is Int? && b is String?) { a == b - a === b + a === b } } fun incompatibleIdentityRegardlessNullabilityWithValueClasses(c: C?, d: D?) { c == d - c === d + c === d } fun incompatibleIdentityRegardlessNullabilityWithValueClassesSmartCast(c: Any?, d: Any?) { if (c is C? && d is D?) { c == d - c === d + c === d } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt index 077d0e19d02..71bab91cee1 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt @@ -122,7 +122,7 @@ fun case_9(x: TypealiasNullableString?) { fun case_10() { val a = Class() - if (a.prop_4 === null || true is Boolean) { + if (a.prop_4 === null || true is Boolean) { if (a.prop_4 != null !== null) { a.prop_4 a.prop_4.equals(null) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt index 44796628e15..21ce50c13d0 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.fir.kt @@ -21,7 +21,7 @@ fun case_1() { */ fun case_2() { var x: Boolean? = true - if (x !== null && try { x = null; true } catch (e: Exception) { false }) { + if (x !== null && try { x = null; true } catch (e: Exception) { false }) { x x.not() } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt index 9fab45fe097..af82054abfb 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.fir.kt @@ -173,7 +173,7 @@ fun case_9(x: TypealiasNullableString?) { fun case_10() { val a = Class() - if (a.prop_4 === null || true) { + if (a.prop_4 === null || true) { if (a.prop_4 != null) { a.prop_4 a.prop_4.equals(null) @@ -419,7 +419,7 @@ fun case_20(b: Boolean) { // TESTCASE NUMBER: 21 fun case_21() { - if (EnumClassWithNullableProperty.B.prop_1 !== null) { + if (EnumClassWithNullableProperty.B.prop_1 !== null) { EnumClassWithNullableProperty.B.prop_1 EnumClassWithNullableProperty.B.prop_1.equals(null) EnumClassWithNullableProperty.B.prop_1.propT @@ -451,7 +451,7 @@ fun case_22(a: (() -> Unit)?) { // TESTCASE NUMBER: 23 fun case_23(a: ((Float) -> Int?)?, b: Float?) { - if (a != null && b !== null) { + if (a != null && b !== null) { val x = a(b) if (x != null) { x @@ -1535,36 +1535,36 @@ open class Case29(a: Int?, val b: Float?, private val c: Unit?, protected val d: } fun case_29(a: Case29) { - if (a.x !== null) a.x.equals(null) - if (a.x !== null) a.x.propT - if (a.x !== null) a.x.propAny - if (a.x !== null) a.x.propNullableT - if (a.x !== null) a.x.propNullableAny - if (a.x !== null) a.x.funT() - if (a.x !== null) a.x.funAny() - if (a.x !== null) a.x.funNullableT() - if (a.x !== null) a.x.funNullableAny() - if (a.x !== null) a.x - if (a.b !== null) a.b.equals(null) - if (a.b !== null) a.b.propT - if (a.b !== null) a.b.propAny - if (a.b !== null) a.b.propNullableT - if (a.b !== null) a.b.propNullableAny - if (a.b !== null) a.b.funT() - if (a.b !== null) a.b.funAny() - if (a.b !== null) a.b.funNullableT() - if (a.b !== null) a.b.funNullableAny() - if (a.b !== null) a.b - if (a.e !== null) a.e.equals(null) - if (a.e !== null) a.e.propT - if (a.e !== null) a.e.propAny - if (a.e !== null) a.e.propNullableT - if (a.e !== null) a.e.propNullableAny - if (a.e !== null) a.e.funT() - if (a.e !== null) a.e.funAny() - if (a.e !== null) a.e.funNullableT() - if (a.e !== null) a.e.funNullableAny() - if (a.e !== null) a.e + if (a.x !== null) a.x.equals(null) + if (a.x !== null) a.x.propT + if (a.x !== null) a.x.propAny + if (a.x !== null) a.x.propNullableT + if (a.x !== null) a.x.propNullableAny + if (a.x !== null) a.x.funT() + if (a.x !== null) a.x.funAny() + if (a.x !== null) a.x.funNullableT() + if (a.x !== null) a.x.funNullableAny() + if (a.x !== null) a.x + if (a.b !== null) a.b.equals(null) + if (a.b !== null) a.b.propT + if (a.b !== null) a.b.propAny + if (a.b !== null) a.b.propNullableT + if (a.b !== null) a.b.propNullableAny + if (a.b !== null) a.b.funT() + if (a.b !== null) a.b.funAny() + if (a.b !== null) a.b.funNullableT() + if (a.b !== null) a.b.funNullableAny() + if (a.b !== null) a.b + if (a.e !== null) a.e.equals(null) + if (a.e !== null) a.e.propT + if (a.e !== null) a.e.propAny + if (a.e !== null) a.e.propNullableT + if (a.e !== null) a.e.propNullableAny + if (a.e !== null) a.e.funT() + if (a.e !== null) a.e.funAny() + if (a.e !== null) a.e.funNullableT() + if (a.e !== null) a.e.funNullableAny() + if (a.e !== null) a.e if (a.f !== null) a.f.equals(null) if (a.f !== null) a.f.propT if (a.f !== null) a.f.propAny @@ -2579,36 +2579,36 @@ sealed class Case30(a: Int?, val b: Float?, private val c: Unit?, protected val } fun case_30(a: Case30) { - if (a.x !== null) a.x.equals(null) - if (a.x !== null) a.x.propT - if (a.x !== null) a.x.propAny - if (a.x !== null) a.x.propNullableT - if (a.x !== null) a.x.propNullableAny - if (a.x !== null) a.x.funT() - if (a.x !== null) a.x.funAny() - if (a.x !== null) a.x.funNullableT() - if (a.x !== null) a.x.funNullableAny() - if (a.x !== null) a.x - if (a.b !== null) a.b.equals(null) - if (a.b !== null) a.b.propT - if (a.b !== null) a.b.propAny - if (a.b !== null) a.b.propNullableT - if (a.b !== null) a.b.propNullableAny - if (a.b !== null) a.b.funT() - if (a.b !== null) a.b.funAny() - if (a.b !== null) a.b.funNullableT() - if (a.b !== null) a.b.funNullableAny() - if (a.b !== null) a.b - if (a.e !== null) a.e.equals(null) - if (a.e !== null) a.e.propT - if (a.e !== null) a.e.propAny - if (a.e !== null) a.e.propNullableT - if (a.e !== null) a.e.propNullableAny - if (a.e !== null) a.e.funT() - if (a.e !== null) a.e.funAny() - if (a.e !== null) a.e.funNullableT() - if (a.e !== null) a.e.funNullableAny() - if (a.e !== null) a.e + if (a.x !== null) a.x.equals(null) + if (a.x !== null) a.x.propT + if (a.x !== null) a.x.propAny + if (a.x !== null) a.x.propNullableT + if (a.x !== null) a.x.propNullableAny + if (a.x !== null) a.x.funT() + if (a.x !== null) a.x.funAny() + if (a.x !== null) a.x.funNullableT() + if (a.x !== null) a.x.funNullableAny() + if (a.x !== null) a.x + if (a.b !== null) a.b.equals(null) + if (a.b !== null) a.b.propT + if (a.b !== null) a.b.propAny + if (a.b !== null) a.b.propNullableT + if (a.b !== null) a.b.propNullableAny + if (a.b !== null) a.b.funT() + if (a.b !== null) a.b.funAny() + if (a.b !== null) a.b.funNullableT() + if (a.b !== null) a.b.funNullableAny() + if (a.b !== null) a.b + if (a.e !== null) a.e.equals(null) + if (a.e !== null) a.e.propT + if (a.e !== null) a.e.propAny + if (a.e !== null) a.e.propNullableT + if (a.e !== null) a.e.propNullableAny + if (a.e !== null) a.e.funT() + if (a.e !== null) a.e.funAny() + if (a.e !== null) a.e.funNullableT() + if (a.e !== null) a.e.funNullableAny() + if (a.e !== null) a.e if (a.f !== null) a.f.equals(null) if (a.f !== null) a.f.propT if (a.f !== null) a.f.propAny @@ -3624,36 +3624,36 @@ enum class Case31(a: Int?, val b: Float?, private val c: Unit?, protected val d: } fun case_31(a: Case31) { - if (a.x !== null) a.x.equals(null) - if (a.x !== null) a.x.propT - if (a.x !== null) a.x.propAny - if (a.x !== null) a.x.propNullableT - if (a.x !== null) a.x.propNullableAny - if (a.x !== null) a.x.funT() - if (a.x !== null) a.x.funAny() - if (a.x !== null) a.x.funNullableT() - if (a.x !== null) a.x.funNullableAny() - if (a.x !== null) a.x - if (a.b !== null) a.b.equals(null) - if (a.b !== null) a.b.propT - if (a.b !== null) a.b.propAny - if (a.b !== null) a.b.propNullableT - if (a.b !== null) a.b.propNullableAny - if (a.b !== null) a.b.funT() - if (a.b !== null) a.b.funAny() - if (a.b !== null) a.b.funNullableT() - if (a.b !== null) a.b.funNullableAny() - if (a.b !== null) a.b - if (a.e !== null) a.e.equals(null) - if (a.e !== null) a.e.propT - if (a.e !== null) a.e.propAny - if (a.e !== null) a.e.propNullableT - if (a.e !== null) a.e.propNullableAny - if (a.e !== null) a.e.funT() - if (a.e !== null) a.e.funAny() - if (a.e !== null) a.e.funNullableT() - if (a.e !== null) a.e.funNullableAny() - if (a.e !== null) a.e + if (a.x !== null) a.x.equals(null) + if (a.x !== null) a.x.propT + if (a.x !== null) a.x.propAny + if (a.x !== null) a.x.propNullableT + if (a.x !== null) a.x.propNullableAny + if (a.x !== null) a.x.funT() + if (a.x !== null) a.x.funAny() + if (a.x !== null) a.x.funNullableT() + if (a.x !== null) a.x.funNullableAny() + if (a.x !== null) a.x + if (a.b !== null) a.b.equals(null) + if (a.b !== null) a.b.propT + if (a.b !== null) a.b.propAny + if (a.b !== null) a.b.propNullableT + if (a.b !== null) a.b.propNullableAny + if (a.b !== null) a.b.funT() + if (a.b !== null) a.b.funAny() + if (a.b !== null) a.b.funNullableT() + if (a.b !== null) a.b.funNullableAny() + if (a.b !== null) a.b + if (a.e !== null) a.e.equals(null) + if (a.e !== null) a.e.propT + if (a.e !== null) a.e.propAny + if (a.e !== null) a.e.propNullableT + if (a.e !== null) a.e.propNullableAny + if (a.e !== null) a.e.funT() + if (a.e !== null) a.e.funAny() + if (a.e !== null) a.e.funNullableT() + if (a.e !== null) a.e.funNullableAny() + if (a.e !== null) a.e if (a.f !== null) a.f.equals(null) if (a.f !== null) a.f.propT if (a.f !== null) a.f.propAny diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/16.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/16.fir.kt index 2f6d3ca7233..6ecdeabdfb1 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/16.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/16.fir.kt @@ -114,7 +114,7 @@ fun case_9(x: String?) { // TESTCASE NUMBER: 10 fun case_10(x: Float?) { - if (true && true && true && x !== null) else return + if (true && true && true && x !== null) else return x x.equals(null) x.propT @@ -465,7 +465,7 @@ fun case_33(x: Any?) { // TESTCASE NUMBER: 34 fun case_34(x: Float?) { (l@ { - if (true && true && true && x !== null) else return@l + if (true && true && true && x !== null) else return@l x x.equals(null) x.propT @@ -477,7 +477,7 @@ fun case_34(x: Float?) { x.funNullableT() x.funNullableAny() }).equals(l@ { - if (true && true && true && x !== null) else return@l + if (true && true && true && x !== null) else return@l x x.equals(null) x.propT diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/17.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/17.fir.kt index d9d3a22427a..3be297029c7 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/17.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/17.fir.kt @@ -113,7 +113,7 @@ fun case_9(x: String?) { // TESTCASE NUMBER: 10 fun case_10(x: Float?) { - if (true && true && true && x !== null) else throw Exception() + if (true && true && true && x !== null) else throw Exception() x x.equals(null) x.propT diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/18.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/18.fir.kt index d43c936a111..d8eba6229a6 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/18.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/18.fir.kt @@ -124,7 +124,7 @@ fun case_9(list: List) { // TESTCASE NUMBER: 10 fun case_10(x: Float?) { while (false) { - if (true && true && true && x !== null) else break + if (true && true && true && x !== null) else break x x.equals(null) x.propT @@ -158,7 +158,7 @@ fun case_11(x: Out<*>?, list: List) { // TESTCASE NUMBER: 12 fun case_12(list: List) { for (element in list) { - if (element === null) continue + if (element === null) continue element element.inv() } @@ -213,7 +213,7 @@ fun case_15(map: MutableMap, y: Nothing?) { // TESTCASE NUMBER: 16 fun case_16(map: Map) { for ((k, v) in map) { - if (k !== implicitNullableNothingProperty && v !== implicitNullableNothingProperty) else { continue } + if (k !== implicitNullableNothingProperty && v !== implicitNullableNothingProperty) else { continue } k k.inv() v diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/28.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/28.fir.kt index 9e4b13388fe..c85d30ed3cb 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/28.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/28.fir.kt @@ -59,7 +59,7 @@ fun case_7(x: DeepObject.A.B.C.D.E.F.G.J?) { // TESTCASE NUMBER: 8 fun case_8(x: Any?) { - if (x?.equals(10) === null) else { + if (x?.equals(10) === null) else { x x.equals(10) } @@ -67,7 +67,7 @@ fun case_8(x: Any?) { // TESTCASE NUMBER: 9 fun case_9(x: Any?) { - if (x?.equals(10) !== null) { + if (x?.equals(10) !== null) { x x.equals(10) } @@ -117,7 +117,7 @@ inline fun case_13(x: Any?) { // TESTCASE NUMBER: 14 inline fun case_14(x: Any?) { - if (x?.equals(10) === null) else { + if (x?.equals(10) === null) else { x x.equals(10) } @@ -125,7 +125,7 @@ inline fun case_14(x: Any?) { // TESTCASE NUMBER: 15 inline fun case_15(x: Any?) { - if (x?.equals(10) !== null) { + if (x?.equals(10) !== null) { x x.equals(10) } @@ -137,7 +137,7 @@ inline fun case_15(x: Any?) { * ISSUES: KT-30369, KT-28262 */ inline fun case_16(x: Any?) { - if (x?.equals(10) === null == true) else { + if (x?.equals(10) === null == true) else { x x.equals(10) } @@ -149,7 +149,7 @@ inline fun case_16(x: Any?) { * ISSUES: KT-30369, KT-28262 */ inline fun case_17(x: Any?) { - if (x?.equals(10) !== null == true) { + if (x?.equals(10) !== null == true) { x x.equals(10) } @@ -161,7 +161,7 @@ inline fun case_17(x: Any?) { * ISSUES: KT-30369, KT-28262, KT-29878 */ inline fun case_18(x: Any?) { - if (x?.equals(10) === null === true) else { + if (x?.equals(10) === null === true) else { x x.equals(10) } @@ -173,7 +173,7 @@ inline fun case_18(x: Any?) { * ISSUES: KT-30369, KT-28262, KT-29878 */ inline fun case_19(x: Any?) { - if (x?.equals(10) !== null === true) { + if (x?.equals(10) !== null === true) { x x.equals(10) } @@ -185,7 +185,7 @@ inline fun case_19(x: Any?) { * ISSUES: KT-30369, KT-28262, KT-29878 */ inline fun case_20(x: Any?) { - if (x?.equals(10) === null !== false) else { + if (x?.equals(10) === null !== false) else { x x.equals(10) } @@ -197,7 +197,7 @@ inline fun case_20(x: Any?) { * ISSUES: KT-30369, KT-28262, KT-29878 */ inline fun case_21(x: Any?) { - if (x?.equals(10) !== null !== false) { + if (x?.equals(10) !== null !== false) { x x.equals(10) } @@ -209,7 +209,7 @@ inline fun case_21(x: Any?) { * ISSUES: KT-30369, KT-28262, KT-29878 */ inline fun case_22(x: Any?) { - if (x?.equals(10) !== null !== true) else { + if (x?.equals(10) !== null !== true) else { x x.equals(10) } @@ -221,7 +221,7 @@ inline fun case_22(x: Any?) { * ISSUES: KT-30369, KT-28262, KT-29878 */ inline fun case_23(x: Any?) { - if (x?.equals(10) === null === false) { + if (x?.equals(10) === null === false) { x x.equals(10) } @@ -233,7 +233,7 @@ inline fun case_23(x: Any?) { * ISSUES: KT-30369, KT-28262 */ inline fun case_24(x: Any?) { - if (x?.equals(10) !== null != true) else { + if (x?.equals(10) !== null != true) else { x x.equals(10) } @@ -245,7 +245,7 @@ inline fun case_24(x: Any?) { * ISSUES: KT-30369, KT-28262 */ inline fun case_25(x: Any?) { - if (x?.equals(10) === null == false) { + if (x?.equals(10) === null == false) { x x.equals(10) } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt index f7a4d602e50..26c7c55ad55 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/3.fir.kt @@ -187,7 +187,7 @@ fun case_16() { } // TESTCASE NUMBER: 17 -val case_17 = if (nullableIntProperty !== null) 0 else { +val case_17 = if (nullableIntProperty !== null) 0 else { nullableIntProperty } @@ -297,7 +297,7 @@ fun case_25(b: Boolean) { } // TESTCASE NUMBER: 26 -fun case_26(a: Int?, b: Int? = if (a !== null) 0 else a) { +fun case_26(a: Int?, b: Int? = if (a !== null) 0 else a) { a b } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/39.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/39.fir.kt index e25b460c6dd..c6b382d1a83 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/39.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/39.fir.kt @@ -19,7 +19,7 @@ fun case_1(x: Number?) { fun case_2(x: Number) { val y: Int? = null - if (x === y) { + if (x === y) { x x.inv() } @@ -29,7 +29,7 @@ fun case_2(x: Number) { fun case_3(x: Number) { var y: Int? = null - if (x === y) { + if (x === y) { x x.inv() } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/5.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/5.fir.kt index 4714ba01bc3..2d80ca49658 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/5.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/5.fir.kt @@ -351,7 +351,7 @@ fun case_15(x: Any?) { } // TESTCASE NUMBER: 16 -fun case_16(a: Any?, b: Int = if (a is Number? && a is Int? && a !== null) a else 0) { +fun case_16(a: Any?, b: Int = if (a is Number? && a is Int? && a !== null) a else 0) { a b b.equals(null) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt index 15917483423..9e2857c0eb9 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt @@ -175,7 +175,7 @@ fun case_10() { val a = Class() val b = null - if (a.prop_4 === b || true) { + if (a.prop_4 === b || true) { if (a.prop_4 != null) { a.prop_4 a.prop_4.equals(null) @@ -307,7 +307,7 @@ fun case_16() { } // TESTCASE NUMBER: 17 -val case_17 = if (nullableIntProperty === implicitNullableNothingProperty) 0 else { +val case_17 = if (nullableIntProperty === implicitNullableNothingProperty) 0 else { nullableIntProperty nullableIntProperty.equals(null) nullableIntProperty.propT @@ -405,7 +405,7 @@ fun case_20(x: Boolean, y: Nothing?) { // TESTCASE NUMBER: 21 fun case_21() { - if (EnumClassWithNullableProperty.A.prop_1 !== implicitNullableNothingProperty) { + if (EnumClassWithNullableProperty.A.prop_1 !== implicitNullableNothingProperty) { EnumClassWithNullableProperty.A.prop_1 EnumClassWithNullableProperty.A.prop_1.equals(null) EnumClassWithNullableProperty.A.prop_1.propT @@ -437,9 +437,9 @@ fun case_22(a: (() -> Unit)?) { // TESTCASE NUMBER: 23 fun case_23(a: ((Float) -> Int?)?, b: Float?, z: Nothing?) { - if (a != z && b !== z && b !== z) { + if (a != z && b !== z && b !== z) { val x = a(b) - if (x != z || x !== implicitNullableNothingProperty) { + if (x != z || x !== implicitNullableNothingProperty) { x x.equals(null) x.propT @@ -512,7 +512,7 @@ fun case_26(a: ((Float) -> Int?)?, b: Float?) { if (a != z == true && b != implicitNullableNothingProperty == true) { val x = a(b) - if (x != implicitNullableNothingProperty == true || z !== x) { + if (x != implicitNullableNothingProperty == true || z !== x) { x x.equals(null) x.propT @@ -613,7 +613,7 @@ fun case_30(a: ((Float) -> Int?)?, b: Float?) { // TESTCASE NUMBER: 31 fun case_31(z1: Boolean?, z: Nothing?) { - if (false || EnumClassWithNullableProperty.A.prop_1 != z && z1 !== z && z1) { + if (false || EnumClassWithNullableProperty.A.prop_1 != z && z1 !== z && z1) { EnumClassWithNullableProperty.A.prop_1 EnumClassWithNullableProperty.A.prop_1.equals(null) EnumClassWithNullableProperty.A.prop_1.propT @@ -652,7 +652,7 @@ fun case_33(a: ((Float) -> Int?)?, b: Float?, c: Boolean?) { } else { val x = a(b) - if (x == z == true && x === z || (c != z && !c)) { + if (x == z == true && x === z || (c != z && !c)) { } else { x @@ -917,7 +917,7 @@ fun case_51() { } // TESTCASE NUMBER: 52 -val case_52 = if (nullableIntProperty !== nullableNothingProperty && nullableNothingProperty != nullableIntProperty) 0 else { +val case_52 = if (nullableIntProperty !== nullableNothingProperty && nullableNothingProperty != nullableIntProperty) 0 else { nullableIntProperty nullableIntProperty.hashCode() } @@ -1003,7 +1003,7 @@ fun case_57(a: (() -> Unit)) { * UNEXPECTED BEHAVIOUR */ fun case_58(a: ((Float) -> Int?)?, b: Float?, z: Nothing?) { - if (a === z && b == z || z == a && z === b) { + if (a === z && b == z || z == a && z === b) { ?")!>a b if (a != z) { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt index db0427a20fb..6641fef664d 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/7.fir.kt @@ -168,7 +168,7 @@ fun case_9(x: TypealiasNullableString?) { fun case_10() { val a = Class() - if (a.prop_4 === null || a.prop_4 === null || true) { + if (a.prop_4 === null || a.prop_4 === null || true) { if (a.prop_4 != null) { a.prop_4 a.prop_4.equals(null) @@ -388,7 +388,7 @@ fun case_20(b: Boolean) { // TESTCASE NUMBER: 21 fun case_21() { val y = null - if (EnumClassWithNullableProperty.A.prop_1 !== null && y != EnumClassWithNullableProperty.A.prop_1) { + if (EnumClassWithNullableProperty.A.prop_1 !== null && y != EnumClassWithNullableProperty.A.prop_1) { EnumClassWithNullableProperty.A.prop_1 EnumClassWithNullableProperty.A.prop_1.equals(null) EnumClassWithNullableProperty.A.prop_1.propT @@ -421,9 +421,9 @@ fun case_22(a: (() -> Unit)?) { // TESTCASE NUMBER: 23 fun case_23(a: ((Float) -> Int?)?, b: Float?, c: Nothing?) { - if (a != null && b !== null || a != c && b !== c) { + if (a != null && b !== null || a != c && b !== c) { val x = a(b) - if (x != null || c !== x) { + if (x != null || c !== x) { x x.equals(null) x.propT @@ -533,7 +533,7 @@ fun case_27(y: Nothing?) { //TESTCASE NUMBER: 28 fun case_28(a: DeepObject.A.B.C.D.E.F.G.J?) = - if (a != null == true == false == false == false == true == false == true == false == false == true == true && a.x !== nullableNothingProperty) { + if (a != null == true == false == false == false == true == false == true == false == false == true == true && a.x !== nullableNothingProperty) { a.x a.equals(null) a.propT @@ -547,13 +547,13 @@ fun case_28(a: DeepObject.A.B.C.D.E.F.G.J?) = } else -1 // TESTCASE NUMBER: 29 -fun case_29(a: Int?, b: Nothing?, c: Int = if (a === b) 0 else a) { +fun case_29(a: Int?, b: Nothing?, c: Int = if (a === b) 0 else a) { a b } // TESTCASE NUMBER: 30 -fun case_30(a: Int?, b: Nothing?, c: Int = if (a === b || a == null) 0 else a) { +fun case_30(a: Int?, b: Nothing?, c: Int = if (a === b || a == null) 0 else a) { a b }