JVM IR: keep original KotlinType in eraseTypeParameters

Otherwise EnhancedNullability annotation instance is lost (for some
reason it's not translated to IR elements), and in the newly added test,
the wrapper type in Java is confused with primitive, and this causes
a platform declaration clash error.

Also make IrTypeArgument.eraseTypeParameters private, since it's not
used outside.
This commit is contained in:
Alexander Udalov
2020-02-05 16:02:52 +01:00
parent 1ae0017401
commit 763cb6dd6f
6 changed files with 39 additions and 1 deletions
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.load.java.JavaVisibilities
@@ -53,6 +54,7 @@ fun IrType.eraseTypeParameters() = when (this) {
is IrSimpleType ->
when (val owner = classifier.owner) {
is IrClass -> IrSimpleTypeImpl(
originalKotlinType,
classifier,
hasQuestionMark,
arguments.map { it.eraseTypeParameters() },
@@ -72,7 +74,7 @@ fun IrType.eraseTypeParameters() = when (this) {
else -> error("Unknown IrType kind: $this")
}
fun IrTypeArgument.eraseTypeParameters(): IrTypeArgument = when (this) {
private fun IrTypeArgument.eraseTypeParameters(): IrTypeArgument = when (this) {
is IrStarProjection -> this
is IrTypeProjection -> makeTypeProjection(type.eraseTypeParameters(), variance)
else -> error("Unknown IrTypeArgument kind: $this")
@@ -0,0 +1,16 @@
// TARGET_BACKEND: JVM
// FILE: E.java
public interface E {
@org.jetbrains.annotations.NotNull
Integer getId();
}
// FILE: box.kt
class EImpl : E {
override fun getId(): Int = 314
}
fun box(): String = if (EImpl().getId() == 314) "OK" else "Fail"
@@ -28169,6 +28169,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/typeMapping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("enhancedPrimitiveInReturnType.kt")
public void testEnhancedPrimitiveInReturnType() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitiveInReturnType.kt");
}
@TestMetadata("enhancedPrimitives.kt")
public void testEnhancedPrimitives() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitives.kt");
@@ -26986,6 +26986,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/typeMapping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("enhancedPrimitiveInReturnType.kt")
public void testEnhancedPrimitiveInReturnType() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitiveInReturnType.kt");
}
@TestMetadata("enhancedPrimitives.kt")
public void testEnhancedPrimitives() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitives.kt");
@@ -26678,6 +26678,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/typeMapping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("enhancedPrimitiveInReturnType.kt")
public void testEnhancedPrimitiveInReturnType() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitiveInReturnType.kt");
}
@TestMetadata("enhancedPrimitives.kt")
public void testEnhancedPrimitives() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitives.kt");
@@ -26678,6 +26678,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/typeMapping"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("enhancedPrimitiveInReturnType.kt")
public void testEnhancedPrimitiveInReturnType() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitiveInReturnType.kt");
}
@TestMetadata("enhancedPrimitives.kt")
public void testEnhancedPrimitives() throws Exception {
runTest("compiler/testData/codegen/box/typeMapping/enhancedPrimitives.kt");