From 93f4a4da10639ed5c361927c51d096cc2270c955 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 28 May 2018 16:57:34 +0300 Subject: [PATCH] IrTypes: star projections Initial implementation, mostly to avoid infinite recursion in cases such as 'Enum<*>'. --- .../src/org/jetbrains/kotlin/ir/types/IrType.kt | 8 ++++++-- .../jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt | 6 +++--- .../org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt | 10 +++++----- .../src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt | 7 +++++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt index 51ebca098a7..5b145879168 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt @@ -20,10 +20,14 @@ interface IrDynamicType : IrType interface IrSimpleType : IrType { val classifier: IrClassifierSymbol val hasQuestionMark: Boolean - val arguments: List + val arguments: List } -interface IrTypeProjection { +interface IrTypeArgument + +interface IrStarProjection : IrTypeArgument + +interface IrTypeProjection : IrTypeArgument { val variance: Variance val type: IrType } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt index 18584d3e484..d1979523979 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrSimpleTypeImpl.kt @@ -16,7 +16,7 @@ class IrSimpleTypeImpl( kotlinType: KotlinType?, override val classifier: IrClassifierSymbol, override val hasQuestionMark: Boolean, - override val arguments: List, + override val arguments: List, annotations: List, variance: Variance ) : IrTypeBase(kotlinType, annotations, variance), IrSimpleType, IrTypeProjection { @@ -24,7 +24,7 @@ class IrSimpleTypeImpl( constructor( classifier: IrClassifierSymbol, hasQuestionMark: Boolean, - arguments: List, + arguments: List, annotations: List ) : this(null, classifier, hasQuestionMark, arguments, annotations, Variance.INVARIANT) @@ -32,7 +32,7 @@ class IrSimpleTypeImpl( kotlinType: KotlinType?, classifier: IrClassifierSymbol, hasQuestionMark: Boolean, - arguments: List, + arguments: List, annotations: List ) : this(kotlinType, classifier, hasQuestionMark, arguments, annotations, Variance.INVARIANT) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt index b2bfeca85ad..55fbdd8cf45 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeBase.kt @@ -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()?.kotlinType \ No newline at end of file + get() = safeAs()?.kotlinType + + +object IrStarProjectionImpl : IrStarProjection \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt index 189dfcdc313..f9e7f09fd4d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt @@ -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) = arguments.map { - // TODO starProjection - translateType(it.type, it.projectionKind) + if (it.isStarProjection) + IrStarProjectionImpl + else + translateType(it.type, it.projectionKind) } }