From 100a6f70ca8953bad2755cf438beade943221ea6 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 15 Jul 2020 10:59:10 +0300 Subject: [PATCH] Relax rules about inferring to Nothing for special calls #KT-37388 Fixed #KT-38427 Fixed #KT-39953 Fixed #KT-38899 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 10 + .../ir/FirBlackBoxCodegenTestGenerated.java | 5 + .../DiagnosticReporterByTrackingStrategy.kt | 4 +- .../calls/smartcasts/DataFlowInfoImpl.kt | 19 +- .../ControlStructureTypingUtils.java | 3 +- .../noNothingValueInsideSpecialCall.kt | 24 ++ .../diagnostics/tests/FunctionReturnTypes.kt | 10 +- .../bound/reservedExpressionSyntax3.kt | 2 +- .../controlStructures/ifElseIntersection.kt | 6 +- .../tests/controlStructures/kt4310.kt | 4 +- .../specialConstructsAndPlatformTypes.kt | 4 +- .../tests/controlStructures/tryReturnType.kt | 10 +- .../dataFlowInfoTraversal/ObjectExpression.kt | 2 +- .../tests/dataFlowInfoTraversal/Return.kt | 2 +- .../tests/exposed/inaccessibleType.kt | 6 +- .../diagnostics/tests/implicitIntersection.kt | 4 +- .../inference/extensionLambdasAndArrow.kt | 4 +- ...itInvokeExtensionWithFunctionalArgument.kt | 2 +- .../tests/inference/nothingType/kt32388.kt | 2 +- .../nullableExpectedTypeFromVariable.fir.kt | 19 + .../nullableExpectedTypeFromVariable.kt | 19 + .../nullableExpectedTypeFromVariable.txt | 10 + .../reifiedParameterWithRecursiveBound.kt | 4 +- ...lCallWithMaterializeAndExpectedType.fir.kt | 8 + ...ecialCallWithMaterializeAndExpectedType.kt | 8 + ...cialCallWithMaterializeAndExpectedType.txt | 4 + .../diagnostics/tests/infos/SmartCasts.kt | 6 +- .../nullabilityAndSmartCasts/AssertNotNull.kt | 2 +- .../tests/nullabilityAndSmartCasts/kt2146.kt | 36 +- .../qualifiedExpression/TypeWithError.kt | 8 +- .../TypeMismatchOnUnaryOperations.kt | 2 +- .../diagnostics/tests/regressions/kt13685.kt | 2 +- .../invoke/extensionValueAsNonExtension.kt | 2 +- .../tests/resolve/newLineLambda.kt | 6 +- .../tests/smartCasts/alwaysNull.kt | 2 +- .../tests/smartCasts/publicVals/delegate.kt | 2 +- .../smartCasts/variables/ifNullAssignment.kt | 2 +- .../postfixNotnullClassIncrement.kt | 2 +- .../varnotnull/prefixNotnullClassIncrement.kt | 2 +- ...citNothingAgainstNotNothingExpectedType.kt | 18 +- .../testData/diagnostics/tests/when/kt9929.kt | 6 +- .../testData/diagnostics/tests/when/kt9972.kt | 4 +- .../testsWithStdLib/tryCatch/assignTry.kt | 4 +- .../expressions/try-expression/p-8/neg/1.1.kt | 16 +- .../contractBuilder/common/neg/4.kt | 2 +- .../diagnostics/notLinked/dfa/pos/1.kt | 324 +++++++++--------- .../diagnostics/notLinked/dfa/pos/2.kt | 2 +- .../diagnostics/notLinked/dfa/pos/36.kt | 2 +- .../diagnostics/notLinked/dfa/pos/6.kt | 2 +- .../diagnostics/notLinked/dfa/pos/64.kt | 4 +- .../checkers/DiagnosticsTestGenerated.java | 10 + .../DiagnosticsUsingJavacTestGenerated.java | 10 + .../codegen/BlackBoxCodegenTestGenerated.java | 5 + .../LightAnalysisModeTestGenerated.java | 5 + .../ir/IrBlackBoxCodegenTestGenerated.java | 5 + 55 files changed, 424 insertions(+), 264 deletions(-) create mode 100644 compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.txt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.txt diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 86fdb5aacba..ddfbc2d8868 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -11357,6 +11357,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.kt"); } + @TestMetadata("nullableExpectedTypeFromVariable.kt") + public void testNullableExpectedTypeFromVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.kt"); + } + @TestMetadata("platformNothingAsUsefulConstraint.kt") public void testPlatformNothingAsUsefulConstraint() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt"); @@ -11366,6 +11371,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte public void testReifiedParameterWithRecursiveBound() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt"); } + + @TestMetadata("specialCallWithMaterializeAndExpectedType.kt") + public void testSpecialCallWithMaterializeAndExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation") diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index b2ff755596c..540ed9e2442 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -12459,6 +12459,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt"); } + @TestMetadata("noNothingValueInsideSpecialCall.kt") + public void testNoNothingValueInsideSpecialCall() throws Exception { + runTest("compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt"); + } + @TestMetadata("plusAssignInsideLambda.kt") public void testPlusAssignInsideLambda() throws Exception { runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index dc48df798b9..bd2e264ba2d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -178,7 +178,9 @@ class DiagnosticReporterByTrackingStrategy( ArgumentTypeMismatchDiagnostic::class.java -> { require(diagnostic is ArgumentTypeMismatchDiagnostic) - val expression = callArgument.safeAs()?.valueArgument?.getArgumentExpression() + val expression = callArgument.safeAs()?.valueArgument?.getArgumentExpression()?.let { + KtPsiUtil.deparenthesize(it) ?: it + } if (expression != null) { if (expression.isNull() && expression is KtConstantExpression) { trace.reportDiagnosticOnce(NULL_FOR_NONNULL_TYPE.on(expression, diagnostic.expectedType)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowInfoImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowInfoImpl.kt index f955ec541bf..9b501927db5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowInfoImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowInfoImpl.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor import org.jetbrains.kotlin.types.typeUtil.contains import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf +import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import org.jetbrains.kotlin.util.javaslang.* import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize import java.util.* @@ -302,9 +303,25 @@ internal class DataFlowInfoImpl private constructor( when { this == null -> other ?: ImmutableLinkedHashSet.empty() other == null -> this - else -> this.intersect(other) + else -> { + // Here we cover the case when "this" has T?!! type and "other" has T + val thisApproximated = approximateDefinitelyNotNullableTypes(this) + val otherApproximated = approximateDefinitelyNotNullableTypes(other) + if (thisApproximated == null && otherApproximated == null || + thisApproximated != null && otherApproximated != null + ) { + this.intersect(other) + } else { + (thisApproximated ?: this).intersect(otherApproximated ?: other) + } + } } + private fun approximateDefinitelyNotNullableTypes(set: ImmutableSet): ImmutableSet? { + if (!set.any { it.isDefinitelyNotNullType }) return null + return set.map { if (it is DefinitelyNotNullType) it.original.makeNotNullable() else it } + } + override fun or(other: DataFlowInfo): DataFlowInfo { if (other === DataFlowInfo.EMPTY) return DataFlowInfo.EMPTY if (this === DataFlowInfo.EMPTY) return DataFlowInfo.EMPTY diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java index cef69295714..1200129ebad 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java @@ -177,8 +177,7 @@ public class ControlStructureTypingUtils { @NotNull KotlinType expectedType, @NotNull LanguageVersionSettings languageVersionSettings ) { - if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference) - || construct == ResolveConstruct.ELVIS + if (construct == ResolveConstruct.ELVIS || TypeUtils.noExpectedType(expectedType) || TypeUtils.isDontCarePlaceholder(expectedType) || KotlinBuiltIns.isUnitOrNullableUnit(expectedType) diff --git a/compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt b/compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt new file mode 100644 index 00000000000..15457606613 --- /dev/null +++ b/compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt @@ -0,0 +1,24 @@ +// WITH_REFLECT +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR + +fun create(modelClass: Class): T { + return if (modelClass.isAssignableFrom(B::class.java)) { + createViewModel() + } else { + throw Exception() + } +} + +@Suppress("UNCHECKED_CAST") +fun createViewModel(): T { + return B() as T +} + +open class A +class B : A() + +fun box(): String { + val r = create(A::class.java) + return if (r is B) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt index 8709c938ffc..5e86c9b152c 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt @@ -67,7 +67,7 @@ fun blockAndAndMismatch5() : Int { (return true) || (return false) } fun blockReturnValueTypeMatch1() : Int { - return if (1 > 2) 1.0 else 2.0 + return if (1 > 2) 1.0 else 2.0 } fun blockReturnValueTypeMatch2() : Int { return if (1 > 2) 1 @@ -134,8 +134,8 @@ fun blockNoReturnIfUnitInOneBranch(): Int { } } } -fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) {} else {} -fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) {} else 2 +fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) {} else {} +fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) {} else 2 val a = return 1 @@ -146,14 +146,14 @@ fun illegalConstantBlock(): String { return 1 } fun illegalIfBody(): Int = - if (1 < 2) 'a' else { 1.0 } + if (1 < 2) 'a' else { 1.0 } fun illegalIfBlock(): Boolean { if (1 < 2) return false else { return 1 } } fun illegalReturnIf(): Char { - return if (1 < 2) 'a' else { 1 } + return if (1 < 2) 'a' else { 1 } } fun returnNothing(): Nothing { diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.kt b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.kt index f070ce5c77c..4cb8f15091a 100644 --- a/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.kt +++ b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.kt @@ -23,7 +23,7 @@ class Test { val Int.c: Int get() = 42 val test1: () -> Right = a.b<Int>.c::foo - val test1a: () -> Right = a.b.c::foo + val test1a: () -> Right = a.b.c::foo val test2: () -> Right = a.b<Int>.c?::foo } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt index 30c36b0c9a1..50ce5450183 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt @@ -25,11 +25,11 @@ fun bind2(r: Option): Option { } fun bind3(r: Option): Option { - return if (r is Some) { + return if (r is Some) { // Diagnoses an error correctly if (true) None() else r - } - else r + } + else r } fun bindWhen(r: Option): Option { diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt b/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt index 761fd6a0092..90d1e3ba2f7 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt @@ -2,9 +2,9 @@ package f fun test(a: Boolean, b: Boolean): Int { - return if(a) { + return if(a) { 1 - } else { + } else { if (b) { 3 } diff --git a/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.kt b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.kt index 6701e083bf1..09c07f57eab 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.kt @@ -30,11 +30,11 @@ val testSafeCall4: String? = J.m[""]?.let { it.toString() } val testIf1: String = if (true) J.s else J.s val testIf2: String? = if (true) J.s else J.s -val testIf3: String = if (true) J.m[""] else J.m[""] +val testIf3: String = if (true) J.m[""] else J.m[""] val testIf4: String? = if (true) J.m[""] else J.m[""] val testWhen1: String = when { else -> J.s } val testWhen2: String? = when { else -> J.s } -val testWhen3: String = when { else -> J.m[""] } +val testWhen3: String = when { else -> J.m[""] } val testWhen4: String? = when { else -> J.m[""] } diff --git a/compiler/testData/diagnostics/tests/controlStructures/tryReturnType.kt b/compiler/testData/diagnostics/tests/controlStructures/tryReturnType.kt index bbc53466ce3..44b9f7eb7a3 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/tryReturnType.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/tryReturnType.kt @@ -14,15 +14,15 @@ fun foo() : Int { } fun bar() : Int = - try { + try { doSmth() - } - catch (e: Exception) { + } + catch (e: Exception) { "" - } + } finally { "" - } + } fun doSmth() {} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt index d06b327315e..a17c535d1b8 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.kt @@ -7,6 +7,6 @@ fun foo() { val a = object { fun baz() = bar(if (x == null) 0 else x) - fun quux(): Int = if (x == null) x else x + fun quux(): Int = if (x == null) x else x } } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt index f238bbddf38..861d7d02672 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.kt @@ -9,7 +9,7 @@ fun foo(): Int { if (x != null) return x val y: Int? = null - if (y == null) return if (y != null) y else y + if (y == null) return if (y != null) y else y val z: Int? = null if (z != null) return if (z == null) z else z diff --git a/compiler/testData/diagnostics/tests/exposed/inaccessibleType.kt b/compiler/testData/diagnostics/tests/exposed/inaccessibleType.kt index 842fef83759..3571333955c 100644 --- a/compiler/testData/diagnostics/tests/exposed/inaccessibleType.kt +++ b/compiler/testData/diagnostics/tests/exposed/inaccessibleType.kt @@ -39,7 +39,7 @@ fun listOf2(x1: T, x2: T): List = null!! fun arrayOf2(x1: T, x2: T): Array = null!! fun test() { - val test1: Base = if (true) d1 else d2 + val test1: Base = if (true) d1 else d2 val test2 = if (true) d1 else d2 @@ -48,10 +48,10 @@ fun test() { else -> d2 } - val test4: Base = when { + val test4: Base = when { true -> d1 else -> d2 - } + } val test5 = select(d1, d2) diff --git a/compiler/testData/diagnostics/tests/implicitIntersection.kt b/compiler/testData/diagnostics/tests/implicitIntersection.kt index 123cf12a936..590eef5ab5b 100644 --- a/compiler/testData/diagnostics/tests/implicitIntersection.kt +++ b/compiler/testData/diagnostics/tests/implicitIntersection.kt @@ -10,13 +10,13 @@ interface C fun foo(b: B) = if (b is A && b is C) b else null // Ok: given explicitly -fun gav(b: B): A? = if (b is A && b is C) b else null +fun gav(b: B): A? = if (b is A && b is C) b else null class My(b: B) { // Error! val x = if (b is A && b is C) b else null // Ok: given explicitly - val y: C? = if (b is A && b is C) b else null + val y: C? = if (b is A && b is C) b else null // Error! fun foo(b: B) = if (b is A && b is C) b else null } diff --git a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt index 1325bf3cbed..cf49b3997d0 100644 --- a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt +++ b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt @@ -6,8 +6,8 @@ fun main() { val x1: String.() -> String = if (true) {{ this }} else {{ this }} val x2: String.() -> String = if (true) {{ -> this }} else {{ -> this }} val x3: () -> String = if (true) {{ -> "this" }} else {{ -> "this" }} - val x4: String.() -> String = if (true) {{ str: String -> "this" }} else {{ str: String -> "this" }} - val x41: String.(String) -> String = if (true) {{ str: String, str2: String -> "this" }} else {{ str: String, str2: String -> "this" }} + val x4: String.() -> String = if (true) {{ str: String -> "this" }} else {{ str: String -> "this" }} + val x41: String.(String) -> String = if (true) {{ str: String, str2: String -> "this" }} else {{ str: String, str2: String -> "this" }} val x42: String.(String) -> String = if (true) {{ str, str2 -> "this" }} else {{ str, str2 -> "this" }} val x5: String.() -> String = if (true) {{ str -> "this" }} else {{ str -> "this" }} val x6: String.() -> String = if (true) {{ str -> "this" }} else {{ "this" }} diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt index a49f68b34e0..2b134d0d5d5 100644 --- a/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt @@ -25,5 +25,5 @@ fun test(s: SelectorFor): Double { val e = s { return p1 } e checkType { _>() } - return null!! + return null!! } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/kt32388.kt b/compiler/testData/diagnostics/tests/inference/nothingType/kt32388.kt index c856bef6bef..e3fb2e1bd72 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/kt32388.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/kt32388.kt @@ -2,7 +2,7 @@ fun Either.recover(f: (A) -> B): Either = when (this) { is Either.Left -> f(this.a).right() - is Either.Right -> this + is Either.Right -> this } fun A.right(): Either = Either.Right(this) diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.fir.kt new file mode 100644 index 00000000000..eb815b7d30f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: +NewInference +// WITH_RUNTIME + +class Foo { + private fun append(map: MutableMap, field: String, appendedValue: T?) { + if (appendedValue != null) { + var currentValue: T? = map[field] + currentValue = if (currentValue == null) { + appendedValue + } else { + or(currentValue, appendedValue) + } + map[field] = currentValue + } + } + + fun or(left: T, right: T): T = left +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.kt b/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.kt new file mode 100644 index 00000000000..dc073ae30c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: +NewInference +// WITH_RUNTIME + +class Foo { + private fun append(map: MutableMap, field: String, appendedValue: T?) { + if (appendedValue != null) { + var currentValue: T? = map[field] + currentValue = if (currentValue == null) { + appendedValue + } else { + or(currentValue, appendedValue) + } + map[field] = currentValue + } + } + + fun or(left: T, right: T): T = left +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.txt b/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.txt new file mode 100644 index 00000000000..8628ab1eb7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.txt @@ -0,0 +1,10 @@ +package + +public final class Foo { + public constructor Foo() + private final fun append(/*0*/ map: kotlin.collections.MutableMap, /*1*/ field: kotlin.String, /*2*/ appendedValue: T?): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun or(/*0*/ left: T, /*1*/ right: T): T + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt index e4c4300bfb8..a96c94f4640 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt @@ -27,8 +27,8 @@ inline fun > testIn(): T { // Unexpected behaviour inline fun > testOut(): T { - return try { - outBound() + return try { + outBound() } catch (ex: Exception) { throw Exception() } diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt new file mode 100644 index 00000000000..ab914441da3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo() { + val s: String? = if (true) materialize() else null +} + +fun materialize(): K = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt new file mode 100644 index 00000000000..a038ae71a58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo() { + val s: String? = if (true) materialize() else null +} + +fun materialize(): K = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.txt b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.txt new file mode 100644 index 00000000000..e76e359aed5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.txt @@ -0,0 +1,4 @@ +package + +public fun foo(): kotlin.Unit +public fun materialize(): K diff --git a/compiler/testData/diagnostics/tests/infos/SmartCasts.kt b/compiler/testData/diagnostics/tests/infos/SmartCasts.kt index 18931e68fe4..fd99a7e520e 100644 --- a/compiler/testData/diagnostics/tests/infos/SmartCasts.kt +++ b/compiler/testData/diagnostics/tests/infos/SmartCasts.kt @@ -142,10 +142,10 @@ fun getStringLength(obj : Any) : Char? { } fun toInt(i: Int?): Int = if (i != null) i else 0 -fun illegalWhenBody(a: Any): Int = when(a) { +fun illegalWhenBody(a: Any): Int = when(a) { is Int -> a - is String -> a -} + is String -> a +} fun illegalWhenBlock(a: Any): Int { when(a) { is Int -> return a diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.kt index b4d9f9645bd..7da916ddce0 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.kt @@ -34,6 +34,6 @@ fun main() { } } - val f : String = a!! + val f : String = a!! checkSubtype(a!!) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt index 073e4f2e281..a074aeecdb6 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt @@ -10,46 +10,46 @@ fun f1(s: Int?): Int { } fun f2(s: Int?): Int { - return when (s) { - !is Int -> s + return when (s) { + !is Int -> s else -> s - } + } } fun f3(s: Int?): Int { - return when (s) { + return when (s) { is Int -> s - else -> s - } + else -> s + } } fun f4(s: Int?): Int { - return when { + return when { s == 4 -> s - s == null -> s + s == null -> s else -> s - } + } } fun f5(s: Int?): Int { - return when (s) { - s -> s + return when (s) { + s -> s s!! -> s s -> s else -> 0 - } + } } fun f6(s: Int?): Int { - return when { + return when { s is Int -> s - else -> s - } + else -> s + } } fun f7(s: Int?): Int { - return when { - s !is Int -> s + return when { + s !is Int -> s else -> s - } + } } diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.kt index 5d95e0c3bae..537aacf1120 100644 --- a/compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.kt +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.kt @@ -17,16 +17,16 @@ fun test1(a: A.B.): A.B. { fun test2(a: A.e.C): A.e.C { val aa: A.e.C = null!! -} +} fun test3(a: a.A.C): a.A.C { val aa: a.A.C = null!! -} +} fun test4(a: A.B.ee): A.B.ee { val aa: A.B.ee = null!! -} +} fun test5(a: A.ee): A.ee { val aa: A.ee = null!! -} \ No newline at end of file +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt index 147fb077a67..74b97d3837b 100644 --- a/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt +++ b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt @@ -3,7 +3,7 @@ fun main() { val a : Int? = null; var v = 1 val b : String = v; - val f : String = a!!; + val f : String = a!!; val g : String = v++; val g1 : String = ++v; val h : String = v--; diff --git a/compiler/testData/diagnostics/tests/regressions/kt13685.kt b/compiler/testData/diagnostics/tests/regressions/kt13685.kt index 72760fb5919..71d427dede6 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt13685.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt13685.kt @@ -2,6 +2,6 @@ // !DIAGNOSTICS: -UNREACHABLE_CODE fun foo() { - val text: List = null!! + val text: List = null!! text.map Any?::toString } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.kt b/compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.kt index e3022a16f8b..e7dc0ec67ae 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.kt @@ -19,5 +19,5 @@ fun foo(): A.() -> Int { val b: Int = foo()(A()) val c: Int = (foo())(A()) - return null!! + return null!! } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/newLineLambda.kt b/compiler/testData/diagnostics/tests/resolve/newLineLambda.kt index c727cd3be2c..128ee9d30a5 100644 --- a/compiler/testData/diagnostics/tests/resolve/newLineLambda.kt +++ b/compiler/testData/diagnostics/tests/resolve/newLineLambda.kt @@ -100,13 +100,13 @@ fun testTwoLambdas() { {} {} - return if (true) { + return if (true) { twoLambdaArgs({}) {} {} - } else { + } else { {} - } + } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt index 912feea1f50..8c8584c556b 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt @@ -4,7 +4,7 @@ fun foo(): String { s = null s?.length s.length - if (s == null) return s!! + if (s == null) return s!! var t: String? = "y" if (t == null) t = "x" var x: Int? = null diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.kt index 508bd95f235..db465a5178c 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.kt @@ -14,7 +14,7 @@ class Example { public fun foo(): String { // Smart cast is not possible if property is delegated - return if (p != null) p else "" + return if (p != null) p else "" } public fun bar(): String { diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.kt index 50ec836f0c6..b4c09df476a 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.kt @@ -3,7 +3,7 @@ fun basic(): String { var current: String? = null - current = if (current == null) "bar" else current + current = if (current == null) "bar" else current return current } diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.kt index 405fe148ede..a8af60b0b89 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.kt @@ -1,7 +1,7 @@ // !WITH_NEW_INFERENCE class MyClass -operator fun MyClass.inc(): MyClass { return null!! } +operator fun MyClass.inc(): MyClass { return null!! } public fun box() : MyClass? { var i : MyClass? diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.kt index 5424ddfdaa2..bc4f25b85b7 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.kt @@ -1,7 +1,7 @@ // !WITH_NEW_INFERENCE class MyClass -operator fun MyClass.inc(): MyClass { return null!! } +operator fun MyClass.inc(): MyClass { return null!! } public fun box() { var i : MyClass? diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAgainstNotNothingExpectedType.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAgainstNotNothingExpectedType.kt index ef986cec344..49cc9bb5c47 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAgainstNotNothingExpectedType.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAgainstNotNothingExpectedType.kt @@ -19,16 +19,16 @@ class Foo { fun test() { if (true) materialize() else null - val x1: String? = if (true) materialize() else null + val x1: String? = if (true) materialize() else null - val x2: String? = if (true) materializeWithGenericArg("") else null + val x2: String? = if (true) materializeWithGenericArg("") else null val x3: String? = if (true) { - if (true) materialize() else null + if (true) materialize() else null } else null val x4: String? = if (true) { - select(materialize(), null) + select(materialize(), null) } else null val x5: String? = select(if (true) materialize() else null, null) @@ -61,7 +61,7 @@ fun test() { val x16: String? = when (boolean) { true -> null - false -> materialize() + false -> materialize() null -> null } @@ -72,7 +72,7 @@ fun test() { } val x18: String? = try { - materialize() + materialize() } catch (e: Exception) { null } @@ -81,11 +81,11 @@ fun test() { val x20: String? = if (true) materialize() else null - val x21: String? = if (true) materialize() else TODO() + val x21: String? = if (true) materialize() else TODO() - val x22: String? = if (true) return else materialize() + val x22: String? = if (true) return else materialize() - val x23: String? = if (true) id(null) else null + val x23: String? = if (true) id(null) else null foo1(if (true) materialize() else null) diff --git a/compiler/testData/diagnostics/tests/when/kt9929.kt b/compiler/testData/diagnostics/tests/when/kt9929.kt index c94ac61f194..e70a58c428e 100644 --- a/compiler/testData/diagnostics/tests/when/kt9929.kt +++ b/compiler/testData/diagnostics/tests/when/kt9929.kt @@ -1,10 +1,10 @@ // !WITH_NEW_INFERENCE -val test: Int = if (true) { +val test: Int = if (true) { when (2) { 1 -> 1 else -> null } -} +} else { 2 -} \ No newline at end of file +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/kt9972.kt b/compiler/testData/diagnostics/tests/when/kt9972.kt index 5d737542c58..529f2cf3f6b 100644 --- a/compiler/testData/diagnostics/tests/when/kt9972.kt +++ b/compiler/testData/diagnostics/tests/when/kt9972.kt @@ -11,12 +11,12 @@ */ fun test1(): Int { - val x: String = if (true) { + val x: String = if (true) { when { true -> Any() else -> null } - } else "" + } else "" return x.hashCode() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.kt index c47eda81680..faf1a1e9a44 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.kt @@ -6,13 +6,13 @@ class ExcA : Exception() class ExcB : Exception() fun test2() { - val s: String? = try { + val s: String? = try { "" } catch (e: ExcA) { null } - catch (e: ExcB) { + catch (e: ExcB) { 10 } s.length diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt index 3b08f028da2..82521f98386 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt @@ -23,12 +23,12 @@ class B(data: T) : A(data) fun case1() { val tryVal: B = - try { + try { throwExceptionA(false) A("") - } catch (e: Exception) { + } catch (e: Exception) { B("") - } + } } @@ -37,10 +37,10 @@ fun case1() { fun case2() { val tryVal: A = - try { + try { throwExceptionA(false) A("") - } catch (e: Exception) { + } catch (e: Exception) { null } } @@ -51,12 +51,12 @@ fun case2() { */ fun case3() { val tryVal: A = - try { + try { throwExceptionA(false) A(2) - } catch (e: ExcA) { + } catch (e: ExcA) { A(null) //diag duplication - } catch (e: ExcB) { + } catch (e: ExcB) { B(null) //diag duplication } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.kt index 3af88c1ea9e..18c90a02217 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/4.kt @@ -14,7 +14,7 @@ import kotlin.contracts.* // TESTCASE NUMBER: 1 fun case_1(): Boolean? { - contract { returnsNotNull() implies (null) } + contract { returnsNotNull() implies (null) } return true } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.kt index 9839fd0df46..57952a2a7f0 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/1.kt @@ -1259,47 +1259,47 @@ open class Case29(a: Int?, val b: Float?, private val c: Unit?, protected val d: if (v != null || this.v != null) this.v w = if (null != null) 10 else null - w - if (w != null) w.equals(null) - if (w != null) w.propT - if (w != null) w.propAny - if (w != null) w.propNullableT - if (w != null) w.propNullableAny - if (w != null) w.funT() - if (w != null) w.funAny() - if (w != null) w.funNullableT() - if (w != null) w.funNullableAny() - if (w != null) w - if (this.w != null) w.equals(null) - if (this.w != null) w.propT - if (this.w != null) w.propAny - if (this.w != null) w.propNullableT - if (this.w != null) w.propNullableAny - if (this.w != null) w.funT() - if (this.w != null) w.funAny() - if (this.w != null) w.funNullableT() - if (this.w != null) w.funNullableAny() - if (this.w != null) w - if (w != null || this.w != null) w.equals(null) - if (w != null || this.w != null) w.propT - if (w != null || this.w != null) w.propAny - if (w != null || this.w != null) w.propNullableT - if (w != null || this.w != null) w.propNullableAny - if (w != null || this.w != null) w.funT() - if (w != null || this.w != null) w.funAny() - if (w != null || this.w != null) w.funNullableT() - if (w != null || this.w != null) w.funNullableAny() - if (w != null || this.w != null) w - if (w != null || this.w != null) this.w.equals(null) - if (w != null || this.w != null) this.w.propT - if (w != null || this.w != null) this.w.propAny - if (w != null || this.w != null) this.w.propNullableT - if (w != null || this.w != null) this.w.propNullableAny - if (w != null || this.w != null) this.w.funT() - if (w != null || this.w != null) this.w.funAny() - if (w != null || this.w != null) this.w.funNullableT() - if (w != null || this.w != null) this.w.funNullableAny() - if (w != null || this.w != null) this.w + w + if (w != null) w.equals(null) + if (w != null) w.propT + if (w != null) w.propAny + if (w != null) w.propNullableT + if (w != null) w.propNullableAny + if (w != null) w.funT() + if (w != null) w.funAny() + if (w != null) w.funNullableT() + if (w != null) w.funNullableAny() + if (w != null) w + if (this.w != null) w.equals(null) + if (this.w != null) w.propT + if (this.w != null) w.propAny + if (this.w != null) w.propNullableT + if (this.w != null) w.propNullableAny + if (this.w != null) w.funT() + if (this.w != null) w.funAny() + if (this.w != null) w.funNullableT() + if (this.w != null) w.funNullableAny() + if (this.w != null) w + if (w != null || this.w != null) w.equals(null) + if (w != null || this.w != null) w.propT + if (w != null || this.w != null) w.propAny + if (w != null || this.w != null) w.propNullableT + if (w != null || this.w != null) w.propNullableAny + if (w != null || this.w != null) w.funT() + if (w != null || this.w != null) w.funAny() + if (w != null || this.w != null) w.funNullableT() + if (w != null || this.w != null) w.funNullableAny() + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(null) + if (w != null || this.w != null) this.w.propT + if (w != null || this.w != null) this.w.propAny + if (w != null || this.w != null) this.w.propNullableT + if (w != null || this.w != null) this.w.propNullableAny + if (w != null || this.w != null) this.w.funT() + if (w != null || this.w != null) this.w.funAny() + if (w != null || this.w != null) this.w.funNullableT() + if (w != null || this.w != null) this.w.funNullableAny() + if (w != null || this.w != null) this.w s = null s.hashCode() @@ -2303,47 +2303,47 @@ sealed class Case30(a: Int?, val b: Float?, private val c: Unit?, protected val if (v != null || this.v != null) this.v w = if (null != null) 10 else null - w - if (w != null) w.equals(null) - if (w != null) w.propT - if (w != null) w.propAny - if (w != null) w.propNullableT - if (w != null) w.propNullableAny - if (w != null) w.funT() - if (w != null) w.funAny() - if (w != null) w.funNullableT() - if (w != null) w.funNullableAny() - if (w != null) w - if (this.w != null) w.equals(null) - if (this.w != null) w.propT - if (this.w != null) w.propAny - if (this.w != null) w.propNullableT - if (this.w != null) w.propNullableAny - if (this.w != null) w.funT() - if (this.w != null) w.funAny() - if (this.w != null) w.funNullableT() - if (this.w != null) w.funNullableAny() - if (this.w != null) w - if (w != null || this.w != null) w.equals(null) - if (w != null || this.w != null) w.propT - if (w != null || this.w != null) w.propAny - if (w != null || this.w != null) w.propNullableT - if (w != null || this.w != null) w.propNullableAny - if (w != null || this.w != null) w.funT() - if (w != null || this.w != null) w.funAny() - if (w != null || this.w != null) w.funNullableT() - if (w != null || this.w != null) w.funNullableAny() - if (w != null || this.w != null) w - if (w != null || this.w != null) this.w.equals(null) - if (w != null || this.w != null) this.w.propT - if (w != null || this.w != null) this.w.propAny - if (w != null || this.w != null) this.w.propNullableT - if (w != null || this.w != null) this.w.propNullableAny - if (w != null || this.w != null) this.w.funT() - if (w != null || this.w != null) this.w.funAny() - if (w != null || this.w != null) this.w.funNullableT() - if (w != null || this.w != null) this.w.funNullableAny() - if (w != null || this.w != null) this.w + w + if (w != null) w.equals(null) + if (w != null) w.propT + if (w != null) w.propAny + if (w != null) w.propNullableT + if (w != null) w.propNullableAny + if (w != null) w.funT() + if (w != null) w.funAny() + if (w != null) w.funNullableT() + if (w != null) w.funNullableAny() + if (w != null) w + if (this.w != null) w.equals(null) + if (this.w != null) w.propT + if (this.w != null) w.propAny + if (this.w != null) w.propNullableT + if (this.w != null) w.propNullableAny + if (this.w != null) w.funT() + if (this.w != null) w.funAny() + if (this.w != null) w.funNullableT() + if (this.w != null) w.funNullableAny() + if (this.w != null) w + if (w != null || this.w != null) w.equals(null) + if (w != null || this.w != null) w.propT + if (w != null || this.w != null) w.propAny + if (w != null || this.w != null) w.propNullableT + if (w != null || this.w != null) w.propNullableAny + if (w != null || this.w != null) w.funT() + if (w != null || this.w != null) w.funAny() + if (w != null || this.w != null) w.funNullableT() + if (w != null || this.w != null) w.funNullableAny() + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(null) + if (w != null || this.w != null) this.w.propT + if (w != null || this.w != null) this.w.propAny + if (w != null || this.w != null) this.w.propNullableT + if (w != null || this.w != null) this.w.propNullableAny + if (w != null || this.w != null) this.w.funT() + if (w != null || this.w != null) this.w.funAny() + if (w != null || this.w != null) this.w.funNullableT() + if (w != null || this.w != null) this.w.funNullableAny() + if (w != null || this.w != null) this.w s = null s.hashCode() @@ -3349,46 +3349,46 @@ enum class Case31(a: Int?, val b: Float?, private val c: Unit?, protected val d: if (v != null || this.v != null) this.v w = if (null != null) 10 else null - if (w != null) w.equals(null) - if (w != null) w.propT - if (w != null) w.propAny - if (w != null) w.propNullableT - if (w != null) w.propNullableAny - if (w != null) w.funT() - if (w != null) w.funAny() - if (w != null) w.funNullableT() - if (w != null) w.funNullableAny() - if (w != null) w - if (this.w != null) w.equals(null) - if (this.w != null) w.propT - if (this.w != null) w.propAny - if (this.w != null) w.propNullableT - if (this.w != null) w.propNullableAny - if (this.w != null) w.funT() - if (this.w != null) w.funAny() - if (this.w != null) w.funNullableT() - if (this.w != null) w.funNullableAny() - if (this.w != null) w - if (w != null || this.w != null) w.equals(null) - if (w != null || this.w != null) w.propT - if (w != null || this.w != null) w.propAny - if (w != null || this.w != null) w.propNullableT - if (w != null || this.w != null) w.propNullableAny - if (w != null || this.w != null) w.funT() - if (w != null || this.w != null) w.funAny() - if (w != null || this.w != null) w.funNullableT() - if (w != null || this.w != null) w.funNullableAny() - if (w != null || this.w != null) w - if (w != null || this.w != null) this.w.equals(null) - if (w != null || this.w != null) this.w.propT - if (w != null || this.w != null) this.w.propAny - if (w != null || this.w != null) this.w.propNullableT - if (w != null || this.w != null) this.w.propNullableAny - if (w != null || this.w != null) this.w.funT() - if (w != null || this.w != null) this.w.funAny() - if (w != null || this.w != null) this.w.funNullableT() - if (w != null || this.w != null) this.w.funNullableAny() - if (w != null || this.w != null) this.w + if (w != null) w.equals(null) + if (w != null) w.propT + if (w != null) w.propAny + if (w != null) w.propNullableT + if (w != null) w.propNullableAny + if (w != null) w.funT() + if (w != null) w.funAny() + if (w != null) w.funNullableT() + if (w != null) w.funNullableAny() + if (w != null) w + if (this.w != null) w.equals(null) + if (this.w != null) w.propT + if (this.w != null) w.propAny + if (this.w != null) w.propNullableT + if (this.w != null) w.propNullableAny + if (this.w != null) w.funT() + if (this.w != null) w.funAny() + if (this.w != null) w.funNullableT() + if (this.w != null) w.funNullableAny() + if (this.w != null) w + if (w != null || this.w != null) w.equals(null) + if (w != null || this.w != null) w.propT + if (w != null || this.w != null) w.propAny + if (w != null || this.w != null) w.propNullableT + if (w != null || this.w != null) w.propNullableAny + if (w != null || this.w != null) w.funT() + if (w != null || this.w != null) w.funAny() + if (w != null || this.w != null) w.funNullableT() + if (w != null || this.w != null) w.funNullableAny() + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(null) + if (w != null || this.w != null) this.w.propT + if (w != null || this.w != null) this.w.propAny + if (w != null || this.w != null) this.w.propNullableT + if (w != null || this.w != null) this.w.propNullableAny + if (w != null || this.w != null) this.w.funT() + if (w != null || this.w != null) this.w.funAny() + if (w != null || this.w != null) this.w.funNullableT() + if (w != null || this.w != null) this.w.funNullableAny() + if (w != null || this.w != null) this.w s = null s.hashCode() @@ -3997,46 +3997,46 @@ object Case32 { if (v != null || this.v != null) this.v w = if (null != null) 10 else null - if (w != null) w.equals(null) - if (w != null) w.propT - if (w != null) w.propAny - if (w != null) w.propNullableT - if (w != null) w.propNullableAny - if (w != null) w.funT() - if (w != null) w.funAny() - if (w != null) w.funNullableT() - if (w != null) w.funNullableAny() - if (w != null) w - if (this.w != null) w.equals(null) - if (this.w != null) w.propT - if (this.w != null) w.propAny - if (this.w != null) w.propNullableT - if (this.w != null) w.propNullableAny - if (this.w != null) w.funT() - if (this.w != null) w.funAny() - if (this.w != null) w.funNullableT() - if (this.w != null) w.funNullableAny() - if (this.w != null) w - if (w != null || this.w != null) w.equals(null) - if (w != null || this.w != null) w.propT - if (w != null || this.w != null) w.propAny - if (w != null || this.w != null) w.propNullableT - if (w != null || this.w != null) w.propNullableAny - if (w != null || this.w != null) w.funT() - if (w != null || this.w != null) w.funAny() - if (w != null || this.w != null) w.funNullableT() - if (w != null || this.w != null) w.funNullableAny() - if (w != null || this.w != null) w - if (w != null || this.w != null) this.w.equals(null) - if (w != null || this.w != null) this.w.propT - if (w != null || this.w != null) this.w.propAny - if (w != null || this.w != null) this.w.propNullableT - if (w != null || this.w != null) this.w.propNullableAny - if (w != null || this.w != null) this.w.funT() - if (w != null || this.w != null) this.w.funAny() - if (w != null || this.w != null) this.w.funNullableT() - if (w != null || this.w != null) this.w.funNullableAny() - if (w != null || this.w != null) this.w + if (w != null) w.equals(null) + if (w != null) w.propT + if (w != null) w.propAny + if (w != null) w.propNullableT + if (w != null) w.propNullableAny + if (w != null) w.funT() + if (w != null) w.funAny() + if (w != null) w.funNullableT() + if (w != null) w.funNullableAny() + if (w != null) w + if (this.w != null) w.equals(null) + if (this.w != null) w.propT + if (this.w != null) w.propAny + if (this.w != null) w.propNullableT + if (this.w != null) w.propNullableAny + if (this.w != null) w.funT() + if (this.w != null) w.funAny() + if (this.w != null) w.funNullableT() + if (this.w != null) w.funNullableAny() + if (this.w != null) w + if (w != null || this.w != null) w.equals(null) + if (w != null || this.w != null) w.propT + if (w != null || this.w != null) w.propAny + if (w != null || this.w != null) w.propNullableT + if (w != null || this.w != null) w.propNullableAny + if (w != null || this.w != null) w.funT() + if (w != null || this.w != null) w.funAny() + if (w != null || this.w != null) w.funNullableT() + if (w != null || this.w != null) w.funNullableAny() + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(null) + if (w != null || this.w != null) this.w.propT + if (w != null || this.w != null) this.w.propAny + if (w != null || this.w != null) this.w.propNullableT + if (w != null || this.w != null) this.w.propNullableAny + if (w != null || this.w != null) this.w.funT() + if (w != null || this.w != null) this.w.funAny() + if (w != null || this.w != null) this.w.funNullableT() + if (w != null || this.w != null) this.w.funNullableAny() + if (w != null || this.w != null) this.w s = null s.hashCode() diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.kt index 0ef38ee85f4..2b677266d74 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/2.kt @@ -385,7 +385,7 @@ fun case_13(b: Boolean, c: Boolean, d: Boolean) { * ISSUES: KT-28329 */ fun case_14(z: Boolean?) { - if (true && true && true && true && EnumClassWithNullableProperty.B.prop_1 != null || z != null || z!! && true && true) { + if (true && true && true && true && EnumClassWithNullableProperty.B.prop_1 != null || z != null || z!! && true && true) { } else { EnumClassWithNullableProperty.B.prop_1 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt index cc6edbbf63a..70697ed8b77 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt @@ -121,7 +121,7 @@ fun case_8(x: Any?, z: Any) { // TESTCASE NUMBER: 9 fun case_9(x: Any?, z: Any) { var y = select(x) ?: return null!! - z == y || throw null!! + z == y || throw null!! x y y.equals(10) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt index 4a237f61f72..21ab40d85cb 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt @@ -685,7 +685,7 @@ fun case_33(a: ((Float) -> Int?)?, b: Float?, c: Boolean?) { fun case_34(z1: Boolean?) { var z = null - if (true && true && true && true && EnumClassWithNullableProperty.A.prop_1 != implicitNullableNothingProperty && EnumClassWithNullableProperty.A.prop_1 !== null && EnumClassWithNullableProperty.A.prop_1 !== z || z1 != implicitNullableNothingProperty || z1!! && true && true) { + if (true && true && true && true && EnumClassWithNullableProperty.A.prop_1 != implicitNullableNothingProperty && EnumClassWithNullableProperty.A.prop_1 !== null && EnumClassWithNullableProperty.A.prop_1 !== z || z1 != implicitNullableNothingProperty || z1!! && true && true) { } else { EnumClassWithNullableProperty.A.prop_1 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/64.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/64.kt index b7c696bc96b..13ab920fcf3 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/64.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/64.kt @@ -84,7 +84,7 @@ class Case5 { fun get(): T { var x = getTN() - x = if (x == null) getT() else x + x = if (x == null) getT() else x x return x } @@ -97,7 +97,7 @@ class Case6 { fun get(): Int { var x = getIntN() - x = if (x == null) getInt() else x + x = if (x == null) getInt() else x x x.equals(10) return x diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 9119fb7febf..938ea81875f 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -11364,6 +11364,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.kt"); } + @TestMetadata("nullableExpectedTypeFromVariable.kt") + public void testNullableExpectedTypeFromVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.kt"); + } + @TestMetadata("platformNothingAsUsefulConstraint.kt") public void testPlatformNothingAsUsefulConstraint() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt"); @@ -11373,6 +11378,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali public void testReifiedParameterWithRecursiveBound() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt"); } + + @TestMetadata("specialCallWithMaterializeAndExpectedType.kt") + public void testSpecialCallWithMaterializeAndExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 691053e09f5..9b0f9ef84d0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -11359,6 +11359,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.kt"); } + @TestMetadata("nullableExpectedTypeFromVariable.kt") + public void testNullableExpectedTypeFromVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/nullableExpectedTypeFromVariable.kt"); + } + @TestMetadata("platformNothingAsUsefulConstraint.kt") public void testPlatformNothingAsUsefulConstraint() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt"); @@ -11368,6 +11373,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing public void testReifiedParameterWithRecursiveBound() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt"); } + + @TestMetadata("specialCallWithMaterializeAndExpectedType.kt") + public void testSpecialCallWithMaterializeAndExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 1b9f41d7b1a..295dbaeeaaf 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13684,6 +13684,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt"); } + @TestMetadata("noNothingValueInsideSpecialCall.kt") + public void testNoNothingValueInsideSpecialCall() throws Exception { + runTest("compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt"); + } + @TestMetadata("plusAssignInsideLambda.kt") public void testPlusAssignInsideLambda() throws Exception { runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 30f5f2ca8f3..481a8b716ad 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13684,6 +13684,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt"); } + @TestMetadata("noNothingValueInsideSpecialCall.kt") + public void testNoNothingValueInsideSpecialCall() throws Exception { + runTest("compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt"); + } + @TestMetadata("plusAssignInsideLambda.kt") public void testPlusAssignInsideLambda() throws Exception { runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 063c3f190d4..b68c85e3687 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -12459,6 +12459,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt"); } + @TestMetadata("noNothingValueInsideSpecialCall.kt") + public void testNoNothingValueInsideSpecialCall() throws Exception { + runTest("compiler/testData/codegen/box/inference/noNothingValueInsideSpecialCall.kt"); + } + @TestMetadata("plusAssignInsideLambda.kt") public void testPlusAssignInsideLambda() throws Exception { runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");