Handle type arguments in IrType.eraseTypeParameters
This commit is contained in:
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
|||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
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.util.*
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||||
@@ -51,7 +52,12 @@ fun IrType.eraseTypeParameters() = when (this) {
|
|||||||
is IrErrorType -> this
|
is IrErrorType -> this
|
||||||
is IrSimpleType ->
|
is IrSimpleType ->
|
||||||
when (val owner = classifier.owner) {
|
when (val owner = classifier.owner) {
|
||||||
is IrClass -> this
|
is IrClass -> IrSimpleTypeImpl(
|
||||||
|
classifier,
|
||||||
|
hasQuestionMark,
|
||||||
|
arguments.map { it.eraseTypeParameters() },
|
||||||
|
annotations
|
||||||
|
)
|
||||||
is IrTypeParameter -> {
|
is IrTypeParameter -> {
|
||||||
val upperBound = owner.erasedUpperBound
|
val upperBound = owner.erasedUpperBound
|
||||||
IrSimpleTypeImpl(
|
IrSimpleTypeImpl(
|
||||||
@@ -66,6 +72,12 @@ fun IrType.eraseTypeParameters() = when (this) {
|
|||||||
else -> error("Unknown IrType kind: $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.
|
* Computes the erased class for this type parameter according to the java erasure rules.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
class MapImpl {
|
||||||
|
{
|
||||||
|
new EmptyMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class EmptyMap<V> : Map<String, V> {
|
||||||
|
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<String> = mutableSetOf()
|
||||||
|
override val values: MutableCollection<V> = mutableSetOf()
|
||||||
|
override val entries : MutableSet<MutableMap.MutableEntry<String, V>> = mutableSetOf()
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public final class EmptyMap</*0*/ V> : kotlin.collections.Map<kotlin.String, V> {
|
||||||
|
public constructor EmptyMap</*0*/ V>()
|
||||||
|
public open val entries: kotlin.collections.MutableSet<kotlin.collections.MutableMap.MutableEntry<kotlin.String, V>>
|
||||||
|
public open val keys: kotlin.collections.MutableSet<kotlin.String>
|
||||||
|
public open val size: kotlin.Int
|
||||||
|
public open val values: kotlin.collections.MutableCollection<V>
|
||||||
|
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<in kotlin.String, in V>): 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()
|
||||||
|
}
|
||||||
Generated
+10
@@ -134,6 +134,11 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
|
|||||||
runTest("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt");
|
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")
|
@TestMetadata("Simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt");
|
runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt");
|
||||||
@@ -787,6 +792,11 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
|
|||||||
runTest("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt");
|
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")
|
@TestMetadata("Simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt");
|
runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt");
|
||||||
|
|||||||
Generated
+5
@@ -132,6 +132,11 @@ public class IrCompileJavaAgainstKotlinTestGenerated extends AbstractIrCompileJa
|
|||||||
runTest("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt");
|
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")
|
@TestMetadata("Simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt");
|
runTest("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user