JVM_IR: keep nullability when remapping type parameters

This commit is contained in:
pyos
2019-12-20 13:43:46 +01:00
committed by Georgy Bronnikov
parent 1b95040934
commit 17d2fda946
7 changed files with 72 additions and 1 deletions
@@ -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(
@@ -0,0 +1,22 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: a.kt
interface I {
fun <T : String> 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().<String>f(null);
}
}
@@ -0,0 +1,9 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
interface I {
fun <T : String> f(x: T?) = x ?: "OK"
}
class C : I
fun box() = C().f<String>(null)
@@ -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");
@@ -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");
@@ -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");
@@ -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");