diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.kt new file mode 100644 index 00000000000..e4678c80353 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Base + +class ParameterizedChild : Base +class Child : Base + +fun elvis(x: K?, y: K): K = TODO() +fun select(x: K, y: K): K = TODO() + +fun myRun(f: () -> V): V = f() + +fun test1(a: ParameterizedChild?, b: Child): Base = myRun { + elvis(a, b) +} + +fun test2(a: S?, b: S): S = myRun { + select(a, b) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.txt b/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.txt new file mode 100644 index 00000000000..b4c95c27016 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.txt @@ -0,0 +1,27 @@ +package + +public fun elvis(/*0*/ x: K?, /*1*/ y: K): K +public fun myRun(/*0*/ f: () -> V): V +public fun select(/*0*/ x: K, /*1*/ y: K): K +public fun test1(/*0*/ a: ParameterizedChild?, /*1*/ b: Child): Base +public fun test2(/*0*/ a: S?, /*1*/ b: S): S + +public interface Base { + 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 +} + +public final class Child : Base { + public constructor Child() + 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 +} + +public final class ParameterizedChild : Base { + public constructor ParameterizedChild() + 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/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 0fa34252c08..671325c87af 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -9823,6 +9823,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/commonSystem/boundOnNullableVariable.kt"); } + @TestMetadata("cstFromNullableChildAndNonParameterizedType.kt") + public void testCstFromNullableChildAndNonParameterizedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.kt"); + } + @TestMetadata("dontCaptureTypeVariable.kt") public void testDontCaptureTypeVariable() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/commonSystem/dontCaptureTypeVariable.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index f84eed9ee18..2942ef9917e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -9818,6 +9818,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/commonSystem/boundOnNullableVariable.kt"); } + @TestMetadata("cstFromNullableChildAndNonParameterizedType.kt") + public void testCstFromNullableChildAndNonParameterizedType() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.kt"); + } + @TestMetadata("dontCaptureTypeVariable.kt") public void testDontCaptureTypeVariable() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/commonSystem/dontCaptureTypeVariable.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt index 4f31b189fc0..2bc244dce62 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.types.checker.TypeCheckerContext.SeveralSupertypesWi import org.jetbrains.kotlin.types.checker.TypeCheckerContext.SupertypesPolicy import org.jetbrains.kotlin.types.typeUtil.asTypeProjection import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny +import org.jetbrains.kotlin.types.typeUtil.isNothing import org.jetbrains.kotlin.types.typeUtil.makeNullable import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -452,7 +453,7 @@ object NullabilityChecker { } private fun TypeCheckerContext.hasPathByNotMarkedNullableNodes(start: SimpleType, end: TypeConstructor) = - anySupertype(start, { !it.isMarkedNullable && it.constructor == end }) { + anySupertype(start, { it.isNothing() || (!it.isMarkedNullable && it.constructor == end) }) { if (it.isMarkedNullable) SupertypesPolicy.None else SupertypesPolicy.LowerIfFlexible }