diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt index f77d181fc05..2b37c95f3de 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol 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.util.* import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.load.java.JavaVisibilities @@ -51,7 +52,12 @@ fun IrType.eraseTypeParameters() = when (this) { is IrErrorType -> this is IrSimpleType -> when (val owner = classifier.owner) { - is IrClass -> this + is IrClass -> IrSimpleTypeImpl( + classifier, + hasQuestionMark, + arguments.map { it.eraseTypeParameters() }, + annotations + ) is IrTypeParameter -> { val upperBound = owner.erasedUpperBound IrSimpleTypeImpl( @@ -66,6 +72,12 @@ fun IrType.eraseTypeParameters() = when (this) { else -> error("Unknown IrType kind: $this") } +fun IrTypeArgument.eraseTypeParameters(): IrTypeArgument = when (this) { + is IrStarProjection -> this + is IrTypeProjection -> makeTypeProjection(type.eraseTypeParameters(), variance) + else -> error("Unknown IrTypeArgument kind: $this") +} + /** * Computes the erased class for this type parameter according to the java erasure rules. */ diff --git a/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.java b/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.java new file mode 100644 index 00000000000..a41f6786d28 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.java @@ -0,0 +1,7 @@ +package test; + +class MapImpl { + { + new EmptyMap(); + } +} diff --git a/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.kt b/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.kt new file mode 100644 index 00000000000..5754c5e4066 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.kt @@ -0,0 +1,14 @@ +package test + +class EmptyMap : Map { + override fun isEmpty() = true + override val size: Int get() = 0 + override fun containsKey(key: String) = false + override fun containsValue(value: V) = false + override fun get(key: String): V? = null + operator fun set(key: String, value: V): V? = null + override val keys : MutableSet = mutableSetOf() + override val values: MutableCollection = mutableSetOf() + override val entries : MutableSet> = mutableSetOf() +} + diff --git a/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.txt b/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.txt new file mode 100644 index 00000000000..c76a6a614a0 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/MapImpl.txt @@ -0,0 +1,20 @@ +package test + +public final class EmptyMap : kotlin.collections.Map { + public constructor EmptyMap() + public open val entries: kotlin.collections.MutableSet> + public open val keys: kotlin.collections.MutableSet + public open val size: kotlin.Int + public open val values: kotlin.collections.MutableCollection + public open fun containsKey(/*0*/ kotlin.String): kotlin.Boolean + public open fun containsValue(/*0*/ V): kotlin.Boolean + public open /*fake_override*/ fun forEach(/*0*/ java.util.function.BiConsumer): kotlin.Unit + public open fun get(/*0*/ kotlin.String): V? + @kotlin.SinceKotlin(version = "1.1") @kotlin.internal.PlatformDependent public open /*fake_override*/ fun getOrDefault(/*0*/ kotlin.String, /*1*/ V): V + public open fun isEmpty(): kotlin.Boolean + public final operator fun set(/*0*/ kotlin.String, /*1*/ V): V? +} + +public/*package*/ open class MapImpl { + public/*package*/ constructor MapImpl() +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java index d6ff99a6e5c..a89c3a0948d 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java @@ -134,6 +134,11 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg runTest("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt"); } + @TestMetadata("MapImpl.kt") + public void testMapImpl() throws Exception { + runTest("compiler/testData/compileJavaAgainstKotlin/class/MapImpl.kt"); + } + @TestMetadata("Simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt"); @@ -787,6 +792,11 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg runTest("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt"); } + @TestMetadata("MapImpl.kt") + public void testMapImpl() throws Exception { + runTest("compiler/testData/compileJavaAgainstKotlin/class/MapImpl.kt"); + } + @TestMetadata("Simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ir/IrCompileJavaAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ir/IrCompileJavaAgainstKotlinTestGenerated.java index a430f9aa211..b4aaf27c656 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ir/IrCompileJavaAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ir/IrCompileJavaAgainstKotlinTestGenerated.java @@ -132,6 +132,11 @@ public class IrCompileJavaAgainstKotlinTestGenerated extends AbstractIrCompileJa runTest("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt"); } + @TestMetadata("MapImpl.kt") + public void testMapImpl() throws Exception { + runTest("compiler/testData/compileJavaAgainstKotlin/class/MapImpl.kt"); + } + @TestMetadata("Simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt");