IrTypes: star projections

Initial implementation, mostly to avoid infinite recursion in cases such
as 'Enum<*>'.
This commit is contained in:
Dmitry Petrov
2018-05-28 16:57:34 +03:00
parent 5b3947da11
commit 93f4a4da10
4 changed files with 19 additions and 12 deletions
@@ -20,10 +20,14 @@ interface IrDynamicType : IrType
interface IrSimpleType : IrType {
val classifier: IrClassifierSymbol
val hasQuestionMark: Boolean
val arguments: List<IrTypeProjection>
val arguments: List<IrTypeArgument>
}
interface IrTypeProjection {
interface IrTypeArgument
interface IrStarProjection : IrTypeArgument
interface IrTypeProjection : IrTypeArgument {
val variance: Variance
val type: IrType
}
@@ -16,7 +16,7 @@ class IrSimpleTypeImpl(
kotlinType: KotlinType?,
override val classifier: IrClassifierSymbol,
override val hasQuestionMark: Boolean,
override val arguments: List<IrTypeProjection>,
override val arguments: List<IrTypeArgument>,
annotations: List<IrCall>,
variance: Variance
) : IrTypeBase(kotlinType, annotations, variance), IrSimpleType, IrTypeProjection {
@@ -24,7 +24,7 @@ class IrSimpleTypeImpl(
constructor(
classifier: IrClassifierSymbol,
hasQuestionMark: Boolean,
arguments: List<IrTypeProjection>,
arguments: List<IrTypeArgument>,
annotations: List<IrCall>
) : this(null, classifier, hasQuestionMark, arguments, annotations, Variance.INVARIANT)
@@ -32,7 +32,7 @@ class IrSimpleTypeImpl(
kotlinType: KotlinType?,
classifier: IrClassifierSymbol,
hasQuestionMark: Boolean,
arguments: List<IrTypeProjection>,
arguments: List<IrTypeArgument>,
annotations: List<IrCall>
) : this(kotlinType, classifier, hasQuestionMark, arguments, annotations, Variance.INVARIANT)
@@ -6,10 +6,7 @@
package org.jetbrains.kotlin.ir.types.impl
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.types.IrDynamicType
import org.jetbrains.kotlin.ir.types.IrErrorType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrTypeProjection
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -38,4 +35,7 @@ class IrDynamicTypeImpl(
val IrType.originalKotlinType: KotlinType?
get() = safeAs<IrTypeBase>()?.kotlinType
get() = safeAs<IrTypeBase>()?.kotlinType
object IrStarProjectionImpl : IrStarProjection
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.types.IrTypeProjection
import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
@@ -89,8 +90,10 @@ class TypeTranslator(
private fun translateTypeArguments(arguments: List<TypeProjection>) =
arguments.map {
// TODO starProjection
translateType(it.type, it.projectionKind)
if (it.isStarProjection)
IrStarProjectionImpl
else
translateType(it.type, it.projectionKind)
}
}