diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt index baeede6ff4a..f398bea1b84 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt @@ -294,7 +294,7 @@ fun IrType.remapTypeParameters(source: IrTypeParametersContainer, target: IrType val classifier = classifier.owner when { classifier is IrTypeParameter && classifier.parent == source -> - target.typeParameters[classifier.index + shift].defaultType + IrSimpleTypeImpl(target.typeParameters[classifier.index + shift].symbol, hasQuestionMark, arguments, annotations) classifier is IrClass -> IrSimpleTypeImpl( diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nonNullableTypeParameter.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nonNullableTypeParameter.kt new file mode 100644 index 00000000000..5d371eb1a55 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nonNullableTypeParameter.kt @@ -0,0 +1,22 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// TARGET_BACKEND: JVM +// FILE: a.kt +interface I { + fun f(x: T) = x +} + +class C : I + +fun box() = try { + B.f() + "FAIL" +} catch (e: IllegalArgumentException) { + "OK" +} + +// FILE: B.java +public class B { + public static String f() { + return new C().f(null); + } +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt new file mode 100644 index 00000000000..f002766378f --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt @@ -0,0 +1,9 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// TARGET_BACKEND: JVM +interface I { + fun f(x: T?) = x ?: "OK" +} + +class C : I + +fun box() = C().f(null) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 79d35bde305..5af4acccfda 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -14514,6 +14514,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt"); } + @TestMetadata("nonNullableTypeParameter.kt") + public void testNonNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nonNullableTypeParameter.kt"); + } + @TestMetadata("nullabilityAssertionOnDispatchReceiver.kt") public void testNullabilityAssertionOnDispatchReceiver() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnDispatchReceiver.kt"); @@ -14539,6 +14544,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt"); } + @TestMetadata("nullableTypeParameter.kt") + public void testNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt"); + } + @TestMetadata("paramAssertionMessage.kt") public void testParamAssertionMessage() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index ddc8288441e..9ca6bdb907b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14514,6 +14514,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt"); } + @TestMetadata("nonNullableTypeParameter.kt") + public void testNonNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nonNullableTypeParameter.kt"); + } + @TestMetadata("nullabilityAssertionOnDispatchReceiver.kt") public void testNullabilityAssertionOnDispatchReceiver() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnDispatchReceiver.kt"); @@ -14539,6 +14544,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt"); } + @TestMetadata("nullableTypeParameter.kt") + public void testNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt"); + } + @TestMetadata("paramAssertionMessage.kt") public void testParamAssertionMessage() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 87a51ec076b..f17e4287a76 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -13364,6 +13364,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt"); } + @TestMetadata("nonNullableTypeParameter.kt") + public void testNonNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nonNullableTypeParameter.kt"); + } + @TestMetadata("nullabilityAssertionOnDispatchReceiver.kt") public void testNullabilityAssertionOnDispatchReceiver() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnDispatchReceiver.kt"); @@ -13389,6 +13394,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt"); } + @TestMetadata("nullableTypeParameter.kt") + public void testNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt"); + } + @TestMetadata("paramAssertionMessage.kt") public void testParamAssertionMessage() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 3b53d40e148..e4cccfcc71c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -13364,6 +13364,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt"); } + @TestMetadata("nonNullableTypeParameter.kt") + public void testNonNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nonNullableTypeParameter.kt"); + } + @TestMetadata("nullabilityAssertionOnDispatchReceiver.kt") public void testNullabilityAssertionOnDispatchReceiver() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnDispatchReceiver.kt"); @@ -13389,6 +13394,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver.kt"); } + @TestMetadata("nullableTypeParameter.kt") + public void testNullableTypeParameter() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt"); + } + @TestMetadata("paramAssertionMessage.kt") public void testParamAssertionMessage() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt");