diff --git a/compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt b/compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt new file mode 100644 index 00000000000..925ff26edd9 --- /dev/null +++ b/compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +NewInference + +class Recursive> : Generic>, MainSupertype +open class Simple : Generic, MainSupertype + +interface Generic + +interface PlaceHolder : Stub +interface Stub + +interface MainSupertype + +interface SpecificStub : Stub +abstract class SpecificSimple : Simple>() + + +fun takeElement(recursive: Recursive<*>?, simpleWithSpecific: Simple>) { + select(recursive, simpleWithSpecific) // T -> intersection type +} + +fun select(x: T?, y: T): T = y + +fun box(): String { + takeElement(null, Simple()) + return "OK" +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index c6d8ff81f42..fc57d1e55da 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -19432,6 +19432,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt") + public void testNoAssertionsWhenNullableTypeParameterReplacedWithIntersectionType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt"); + doTest(fileName); + } + @TestMetadata("noCapturingForTypesWithTypeVariables.kt") public void testNoCapturingForTypesWithTypeVariables() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index f6278348742..983f1117751 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -19432,6 +19432,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt") + public void testNoAssertionsWhenNullableTypeParameterReplacedWithIntersectionType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt"); + doTest(fileName); + } + @TestMetadata("noCapturingForTypesWithTypeVariables.kt") public void testNoCapturingForTypesWithTypeVariables() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 4e3f17f3dea..29a47233627 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -19432,6 +19432,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt") + public void testNoAssertionsWhenNullableTypeParameterReplacedWithIntersectionType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt"); + doTest(fileName); + } + @TestMetadata("noCapturingForTypesWithTypeVariables.kt") public void testNoCapturingForTypesWithTypeVariables() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 9c228a146e1..c816e97b65f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -265,6 +265,14 @@ public class TypeUtils { if (isTypeParameter(type)) { return hasNullableSuperType(type); } + + TypeConstructor constructor = type.getConstructor(); + if (constructor instanceof IntersectionTypeConstructor) { + for (KotlinType supertype : constructor.getSupertypes()) { + if (isNullableType(supertype)) return true; + } + } + return false; } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index d05a1b62df8..37405e168b1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -26423,6 +26423,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive or add it to whitelist for that."); } + @TestMetadata("noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt") + public void testNoAssertionsWhenNullableTypeParameterReplacedWithIntersectionType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt"); + doTest(fileName); + } + @TestMetadata("noCapturingForTypesWithTypeVariables.kt") public void testNoCapturingForTypesWithTypeVariables() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/noCapturingForTypesWithTypeVariables.kt");