diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java new file mode 100644 index 00000000000..e69de29bb2d diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt index 2174c009a62..9d36037fec5 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt @@ -23,15 +23,6 @@ class TrivialConstraintTypeInferenceOracle private constructor(context: TypeSyst return constraint.kind == ConstraintKind.LOWER && constraint.type.typeConstructor().isNothingConstructor() } - // This function controls the choice between sub and super result type - // Even that Nothing(?) is the most specific type for subtype, it doesn't bring valuable information to the user, - // therefore it is discriminated in favor of supertype - fun isSuitableResultedType( - resultType: KotlinTypeMarker - ): Boolean { - return !resultType.typeConstructor().isNothingConstructor() - } - // It's possible to generate Nothing-like constraints inside incorporation mechanism: // For instance, when two type variables are in subtyping relation `T <: K`, after incorporation // there will be constraint `approximation(out K) <: K` => `Nothing <: K`, which is innocent diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.kt b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.kt index 4cb8f15091a..f070ce5c77c 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/controlFlowAnalysis/throwInLambda.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/throwInLambda.kt index 08216a5ae4b..faa28f2353d 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/throwInLambda.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/throwInLambda.kt @@ -8,6 +8,6 @@ fun foo(): String { } fun bar(): String { val x = fn() ?: return "" - val y = x?.let { throw Exception() } ?: "unreachable" - return y + val y = x?.let { throw Exception() } ?: "unreachable" + return y } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.kt index 2b134d0d5d5..a49f68b34e0 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/inferArgumentToNothingFromNullConstant.kt b/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.kt new file mode 100644 index 00000000000..097154888dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE + +class Out(result: T?) + +fun main() { + val a = Out(null) + + ")!>a + + var b: Out? = null + b = a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.txt b/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.txt new file mode 100644 index 00000000000..9181b91daca --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.txt @@ -0,0 +1,10 @@ +package + +public fun main(): kotlin.Unit + +public final class Out { + public constructor Out(/*0*/ result: T?) + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.kt b/compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.kt index 52abf154c34..34f0d485c25 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.kt @@ -1,12 +1,12 @@ -// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE fun select2(x: K, y: K): K = TODO() fun select3(x: K, y: K, z: K): K = TODO() fun test2(f: ((String) -> Int)?) { - val a0: ((Int) -> Int)? = select2({ it -> it }, null) - val b0: ((Nothing) -> Unit)? = select2({ it -> it }, null) + val a0: ((Int) -> Int)? = select2({ it -> it }, null) + val b0: ((Nothing) -> Unit)? = select2({ it -> it }, null) select3({ it.length }, f, null) } diff --git a/compiler/testData/diagnostics/tests/regressions/kt13685.kt b/compiler/testData/diagnostics/tests/regressions/kt13685.kt index 3d3772577f7..3e161815ad4 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 e7dc0ec67ae..e3022a16f8b 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/smartCasts/alwaysNull.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.kt index 8c8584c556b..912feea1f50 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/varnotnull/postfixNotnullClassIncrement.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.kt index a8af60b0b89..405fe148ede 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 bc4f25b85b7..5424ddfdaa2 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/when/whenAndLambdaWithExpectedType.kt b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt index 4011f9bdcc4..afa25e6ef56 100644 --- a/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt +++ b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt @@ -7,19 +7,19 @@ val test1: (String) -> Boolean = val test2: (String) -> Boolean = when { - true -> {{ true }} + true -> {{ true }} else -> null!! } val test3: (String) -> Boolean = when { - true -> { s -> true } + true -> { s -> true } else -> null!! } val test4: (String) -> Boolean = when { - true -> { s1, s2 -> true } + true -> { s1, s2 -> true } else -> null!! } diff --git a/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt index 51c460c3797..87fcc28d214 100644 --- a/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt +++ b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.kt @@ -6,7 +6,7 @@ val test1 = when { } val test1a: () -> Boolean = when { - true -> { { true } } + true -> { { true } } else -> TODO() } @@ -33,7 +33,7 @@ val test3 = when { } val test3a: () -> Boolean = when { - true -> { { true } } - true -> { { true } } + true -> { { true } } + true -> { { true } } else -> TODO() } \ No newline at end of file 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 90ebb9e6e15..cc3f0abe5a6 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 1eb882be842..1161c2964fe 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt @@ -123,8 +123,8 @@ 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!! + var y = select(x) ?: return null!! + z == y || throw null!! x y y.equals(10) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt index ed19e72e61a..608202d6df6 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/4.kt @@ -285,7 +285,7 @@ fun case_24(a: ((() -> Unit) -> Unit), b: (() -> Unit)) { } // TESTCASE NUMBER: 25 -fun case_25(a: (() -> Unit) -> Unit, b: (() -> Unit) -> Unit = if (a == null) kotlin.Unit) -> kotlin.Unit & kotlin.Nothing")!>a else {{}}) { +fun case_25(a: (() -> Unit) -> Unit, b: (() -> Unit) -> Unit = if (a == null) kotlin.Unit) -> kotlin.Unit & kotlin.Nothing"), DEBUG_INFO_SMARTCAST!>a else {{}}) { kotlin.Unit) -> kotlin.Unit")!>a kotlin.Unit) -> kotlin.Unit")!>b } 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 0691f5220ce..3121eff8fa0 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt @@ -686,7 +686,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/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index c0f35b27b0c..a177836d105 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10602,6 +10602,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.kt"); } + @TestMetadata("inferArgumentToNothingFromNullConstant.kt") + public void testInferArgumentToNothingFromNullConstant() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.kt"); + } + @TestMetadata("kt24490.kt") public void testKt24490() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/kt24490.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index a23066903ef..8bba20adcd8 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -10597,6 +10597,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.kt"); } + @TestMetadata("inferArgumentToNothingFromNullConstant.kt") + public void testInferArgumentToNothingFromNullConstant() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/inferArgumentToNothingFromNullConstant.kt"); + } + @TestMetadata("kt24490.kt") public void testKt24490() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/kt24490.kt");