[FIR] Add ConeKotlinTypeConflictingProjection, return it from substituteArgument instead of ConeStarProjection in appropriate cases, remove plus operator from ProjectionKind
This commit is contained in:
committed by
teamcityserver
parent
b85846c0c0
commit
ca970f0a8b
+1
@@ -312,6 +312,7 @@ internal object ConeTypeCompatibilityChecker {
|
||||
// considered compatible.
|
||||
is ConeKotlinTypeProjectionIn -> BoundTypeArgument(coneTypeProjection.type, Variance.IN_VARIANCE)
|
||||
is ConeKotlinTypeProjectionOut -> BoundTypeArgument(coneTypeProjection.type, Variance.OUT_VARIANCE)
|
||||
is ConeKotlinTypeConflictingProjection -> BoundTypeArgument(coneTypeProjection.type, Variance.INVARIANT)
|
||||
is ConeKotlinType ->
|
||||
when ((typeParameter as? FirTypeParameter)?.variance) {
|
||||
Variance.IN_VARIANCE -> BoundTypeArgument(coneTypeProjection.type, Variance.IN_VARIANCE)
|
||||
|
||||
@@ -15,16 +15,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.foldMap
|
||||
|
||||
enum class ProjectionKind {
|
||||
STAR, IN, OUT, INVARIANT;
|
||||
|
||||
operator fun plus(other: ProjectionKind): ProjectionKind {
|
||||
return when {
|
||||
this == other -> this
|
||||
this == STAR || other == STAR -> STAR
|
||||
this == INVARIANT -> other
|
||||
other == INVARIANT -> this
|
||||
else -> STAR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ConeTypeProjection : TypeArgumentMarker {
|
||||
@@ -54,6 +44,11 @@ data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : Cone
|
||||
get() = ProjectionKind.OUT
|
||||
}
|
||||
|
||||
data class ConeKotlinTypeConflictingProjection(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
|
||||
override val kind: ProjectionKind
|
||||
get() = ProjectionKind.INVARIANT
|
||||
}
|
||||
|
||||
val ConeTypeProjection.type: ConeKotlinType?
|
||||
get() = when (this) {
|
||||
ConeStarProjection -> null
|
||||
|
||||
@@ -59,6 +59,7 @@ private fun ConeKotlinType.renderAttributes(): String {
|
||||
fun ConeTypeProjection.render(): String {
|
||||
return when (this) {
|
||||
ConeStarProjection -> "*"
|
||||
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.render()}"
|
||||
is ConeKotlinTypeProjectionIn -> "in ${type.render()}"
|
||||
is ConeKotlinTypeProjectionOut -> "out ${type.render()}"
|
||||
is ConeKotlinType -> render()
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.classId
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.typeContext
|
||||
@@ -19,6 +18,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
@@ -165,16 +165,16 @@ class Fir2IrTypeConverter(
|
||||
}
|
||||
|
||||
private fun ConeTypeProjection.toIrTypeArgument(typeContext: ConversionTypeContext): IrTypeArgument {
|
||||
fun toIrTypeArgument(type: ConeKotlinType, variance: Variance): IrTypeProjection {
|
||||
val irType = type.toIrType(typeContext)
|
||||
return makeTypeProjection(irType, if (typeContext.invariantProjection) Variance.INVARIANT else variance)
|
||||
}
|
||||
|
||||
return when (this) {
|
||||
ConeStarProjection -> IrStarProjectionImpl
|
||||
is ConeKotlinTypeProjectionIn -> {
|
||||
val irType = this.type.toIrType(typeContext)
|
||||
makeTypeProjection(irType, if (typeContext.invariantProjection) Variance.INVARIANT else Variance.IN_VARIANCE)
|
||||
}
|
||||
is ConeKotlinTypeProjectionOut -> {
|
||||
val irType = this.type.toIrType(typeContext)
|
||||
makeTypeProjection(irType, if (typeContext.invariantProjection) Variance.INVARIANT else Variance.OUT_VARIANCE)
|
||||
}
|
||||
is ConeKotlinTypeProjectionIn -> toIrTypeArgument(this.type, Variance.IN_VARIANCE)
|
||||
is ConeKotlinTypeProjectionOut -> toIrTypeArgument(this.type, Variance.OUT_VARIANCE)
|
||||
is ConeKotlinTypeConflictingProjection -> toIrTypeArgument(this.type, Variance.INVARIANT)
|
||||
is ConeKotlinType -> {
|
||||
if (this is ConeCapturedType && this in capturedTypeCache && this.isRecursive(mutableSetOf())) {
|
||||
// Recursive captured type, e.g., Recursive<R> where R : Recursive<R>, ...
|
||||
|
||||
@@ -107,12 +107,32 @@ private fun mapTypeAliasArguments(
|
||||
else -> mappedType
|
||||
}
|
||||
|
||||
return when (mappedProjection.kind + projection.kind) {
|
||||
ProjectionKind.STAR -> ConeStarProjection
|
||||
ProjectionKind.IN -> ConeKotlinTypeProjectionIn(mappedType)
|
||||
ProjectionKind.OUT -> ConeKotlinTypeProjectionOut(mappedType)
|
||||
ProjectionKind.INVARIANT -> mappedType
|
||||
fun convertProjectionKindToConeTypeProjection(projectionKind: ProjectionKind): ConeTypeProjection {
|
||||
return when (projectionKind) {
|
||||
ProjectionKind.STAR -> ConeStarProjection
|
||||
ProjectionKind.IN -> ConeKotlinTypeProjectionIn(mappedType)
|
||||
ProjectionKind.OUT -> ConeKotlinTypeProjectionOut(mappedType)
|
||||
ProjectionKind.INVARIANT -> mappedType
|
||||
}
|
||||
}
|
||||
|
||||
if (mappedProjection.kind == projection.kind) {
|
||||
return convertProjectionKindToConeTypeProjection(mappedProjection.kind)
|
||||
}
|
||||
|
||||
if (mappedProjection.kind == ProjectionKind.STAR || projection.kind == ProjectionKind.STAR) {
|
||||
return ConeStarProjection
|
||||
}
|
||||
|
||||
if (mappedProjection.kind == ProjectionKind.INVARIANT) {
|
||||
return convertProjectionKindToConeTypeProjection(projection.kind)
|
||||
}
|
||||
|
||||
if (projection.kind == ProjectionKind.INVARIANT) {
|
||||
return convertProjectionKindToConeTypeProjection(mappedProjection.kind)
|
||||
}
|
||||
|
||||
return ConeKotlinTypeConflictingProjection(mappedType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ private fun ConeTypeProjection.renderForDebugInfo(): String {
|
||||
ConeStarProjection -> "*"
|
||||
is ConeKotlinTypeProjectionIn -> "in ${type.renderForDebugInfo()}"
|
||||
is ConeKotlinTypeProjectionOut -> "out ${type.renderForDebugInfo()}"
|
||||
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.renderForDebugInfo()}"
|
||||
is ConeKotlinType -> renderForDebugInfo()
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -162,6 +162,7 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
|
||||
ConeStarProjection -> "*"
|
||||
is ConeKotlinTypeProjectionIn -> "in ${type.renderTypeAsKotlinType()}"
|
||||
is ConeKotlinTypeProjectionOut -> "out ${type.renderTypeAsKotlinType()}"
|
||||
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.renderTypeAsKotlinType()}"
|
||||
is ConeKotlinType -> renderTypeAsKotlinType()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user