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:
@@ -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"
|
||||
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user