[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.
|
// considered compatible.
|
||||||
is ConeKotlinTypeProjectionIn -> BoundTypeArgument(coneTypeProjection.type, Variance.IN_VARIANCE)
|
is ConeKotlinTypeProjectionIn -> BoundTypeArgument(coneTypeProjection.type, Variance.IN_VARIANCE)
|
||||||
is ConeKotlinTypeProjectionOut -> BoundTypeArgument(coneTypeProjection.type, Variance.OUT_VARIANCE)
|
is ConeKotlinTypeProjectionOut -> BoundTypeArgument(coneTypeProjection.type, Variance.OUT_VARIANCE)
|
||||||
|
is ConeKotlinTypeConflictingProjection -> BoundTypeArgument(coneTypeProjection.type, Variance.INVARIANT)
|
||||||
is ConeKotlinType ->
|
is ConeKotlinType ->
|
||||||
when ((typeParameter as? FirTypeParameter)?.variance) {
|
when ((typeParameter as? FirTypeParameter)?.variance) {
|
||||||
Variance.IN_VARIANCE -> BoundTypeArgument(coneTypeProjection.type, Variance.IN_VARIANCE)
|
Variance.IN_VARIANCE -> BoundTypeArgument(coneTypeProjection.type, Variance.IN_VARIANCE)
|
||||||
|
|||||||
@@ -15,16 +15,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.foldMap
|
|||||||
|
|
||||||
enum class ProjectionKind {
|
enum class ProjectionKind {
|
||||||
STAR, IN, OUT, INVARIANT;
|
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 {
|
sealed class ConeTypeProjection : TypeArgumentMarker {
|
||||||
@@ -54,6 +44,11 @@ data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : Cone
|
|||||||
get() = ProjectionKind.OUT
|
get() = ProjectionKind.OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ConeKotlinTypeConflictingProjection(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
|
||||||
|
override val kind: ProjectionKind
|
||||||
|
get() = ProjectionKind.INVARIANT
|
||||||
|
}
|
||||||
|
|
||||||
val ConeTypeProjection.type: ConeKotlinType?
|
val ConeTypeProjection.type: ConeKotlinType?
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
ConeStarProjection -> null
|
ConeStarProjection -> null
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ private fun ConeKotlinType.renderAttributes(): String {
|
|||||||
fun ConeTypeProjection.render(): String {
|
fun ConeTypeProjection.render(): String {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
ConeStarProjection -> "*"
|
ConeStarProjection -> "*"
|
||||||
|
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.render()}"
|
||||||
is ConeKotlinTypeProjectionIn -> "in ${type.render()}"
|
is ConeKotlinTypeProjectionIn -> "in ${type.render()}"
|
||||||
is ConeKotlinTypeProjectionOut -> "out ${type.render()}"
|
is ConeKotlinTypeProjectionOut -> "out ${type.render()}"
|
||||||
is ConeKotlinType -> 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.expressions.classId
|
||||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
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.substitution.AbstractConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.typeContext
|
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.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
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.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.types.impl.makeTypeProjection
|
||||||
@@ -165,16 +165,16 @@ class Fir2IrTypeConverter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun ConeTypeProjection.toIrTypeArgument(typeContext: ConversionTypeContext): IrTypeArgument {
|
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) {
|
return when (this) {
|
||||||
ConeStarProjection -> IrStarProjectionImpl
|
ConeStarProjection -> IrStarProjectionImpl
|
||||||
is ConeKotlinTypeProjectionIn -> {
|
is ConeKotlinTypeProjectionIn -> toIrTypeArgument(this.type, Variance.IN_VARIANCE)
|
||||||
val irType = this.type.toIrType(typeContext)
|
is ConeKotlinTypeProjectionOut -> toIrTypeArgument(this.type, Variance.OUT_VARIANCE)
|
||||||
makeTypeProjection(irType, if (typeContext.invariantProjection) Variance.INVARIANT else Variance.IN_VARIANCE)
|
is ConeKotlinTypeConflictingProjection -> toIrTypeArgument(this.type, Variance.INVARIANT)
|
||||||
}
|
|
||||||
is ConeKotlinTypeProjectionOut -> {
|
|
||||||
val irType = this.type.toIrType(typeContext)
|
|
||||||
makeTypeProjection(irType, if (typeContext.invariantProjection) Variance.INVARIANT else Variance.OUT_VARIANCE)
|
|
||||||
}
|
|
||||||
is ConeKotlinType -> {
|
is ConeKotlinType -> {
|
||||||
if (this is ConeCapturedType && this in capturedTypeCache && this.isRecursive(mutableSetOf())) {
|
if (this is ConeCapturedType && this in capturedTypeCache && this.isRecursive(mutableSetOf())) {
|
||||||
// Recursive captured type, e.g., Recursive<R> where R : Recursive<R>, ...
|
// Recursive captured type, e.g., Recursive<R> where R : Recursive<R>, ...
|
||||||
|
|||||||
@@ -107,12 +107,32 @@ private fun mapTypeAliasArguments(
|
|||||||
else -> mappedType
|
else -> mappedType
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (mappedProjection.kind + projection.kind) {
|
fun convertProjectionKindToConeTypeProjection(projectionKind: ProjectionKind): ConeTypeProjection {
|
||||||
ProjectionKind.STAR -> ConeStarProjection
|
return when (projectionKind) {
|
||||||
ProjectionKind.IN -> ConeKotlinTypeProjectionIn(mappedType)
|
ProjectionKind.STAR -> ConeStarProjection
|
||||||
ProjectionKind.OUT -> ConeKotlinTypeProjectionOut(mappedType)
|
ProjectionKind.IN -> ConeKotlinTypeProjectionIn(mappedType)
|
||||||
ProjectionKind.INVARIANT -> 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 -> "*"
|
ConeStarProjection -> "*"
|
||||||
is ConeKotlinTypeProjectionIn -> "in ${type.renderForDebugInfo()}"
|
is ConeKotlinTypeProjectionIn -> "in ${type.renderForDebugInfo()}"
|
||||||
is ConeKotlinTypeProjectionOut -> "out ${type.renderForDebugInfo()}"
|
is ConeKotlinTypeProjectionOut -> "out ${type.renderForDebugInfo()}"
|
||||||
|
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.renderForDebugInfo()}"
|
||||||
is ConeKotlinType -> renderForDebugInfo()
|
is ConeKotlinType -> renderForDebugInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -162,6 +162,7 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
|
|||||||
ConeStarProjection -> "*"
|
ConeStarProjection -> "*"
|
||||||
is ConeKotlinTypeProjectionIn -> "in ${type.renderTypeAsKotlinType()}"
|
is ConeKotlinTypeProjectionIn -> "in ${type.renderTypeAsKotlinType()}"
|
||||||
is ConeKotlinTypeProjectionOut -> "out ${type.renderTypeAsKotlinType()}"
|
is ConeKotlinTypeProjectionOut -> "out ${type.renderTypeAsKotlinType()}"
|
||||||
|
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.renderTypeAsKotlinType()}"
|
||||||
is ConeKotlinType -> renderTypeAsKotlinType()
|
is ConeKotlinType -> renderTypeAsKotlinType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user