diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt index fa521131f83..33d2c46d9b3 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt @@ -322,7 +322,11 @@ fun ConeIntersectionType.mapTypes(func: (ConeKotlinType) -> ConeKotlinType): Con return ConeIntersectionType(intersectedTypes.map(func), alternativeType?.let(func)) } -sealed class ConeStubType(val variable: ConeTypeVariable, override val nullability: ConeNullability) : StubTypeMarker, ConeSimpleKotlinType() { +data class ConeStubTypeConstructor(val variable: ConeTypeVariable, val isTypeVariableInSubtyping: Boolean) : TypeConstructorMarker + +sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker, + ConeSimpleKotlinType() { + override val typeArguments: Array get() = emptyArray() @@ -335,7 +339,7 @@ sealed class ConeStubType(val variable: ConeTypeVariable, override val nullabili other as ConeStubType - if (variable != other.variable) return false + if (constructor != other.constructor) return false if (nullability != other.nullability) return false return true @@ -343,14 +347,16 @@ sealed class ConeStubType(val variable: ConeTypeVariable, override val nullabili override fun hashCode(): Int { var result = 0 - result = 31 * result + variable.hashCode() + result = 31 * result + constructor.hashCode() result = 31 * result + nullability.hashCode() return result } } -class ConeStubTypeForBuilderInference(variable: ConeTypeVariable, nullability: ConeNullability) : ConeStubType(variable, nullability) -class ConeStubTypeForTypeVariableInSubtyping(variable: ConeTypeVariable, nullability: ConeNullability) : ConeStubType(variable, nullability) +open class ConeStubTypeForBuilderInference(variable: ConeTypeVariable, nullability: ConeNullability) : + ConeStubType(ConeStubTypeConstructor(variable, isTypeVariableInSubtyping = false), nullability) +class ConeStubTypeForTypeVariableInSubtyping(variable: ConeTypeVariable, nullability: ConeNullability) : + ConeStubType(ConeStubTypeConstructor(variable, isTypeVariableInSubtyping = true), nullability) open class ConeTypeVariable(name: String, originalTypeParameter: TypeParameterMarker? = null) : TypeVariableMarker { val typeConstructor = ConeTypeVariableTypeConstructor(name, originalTypeParameter) diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt index 1eef81c118f..911f1ac69da 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt @@ -46,8 +46,8 @@ fun ConeKotlinType.render(): String { postfix = ")" ) } - is ConeStubTypeForBuilderInference -> "${renderAttributes()}Stub (builder inference): $variable" - is ConeStubType -> "${renderAttributes()}Stub (subtyping): $variable" + is ConeStubTypeForBuilderInference -> "${renderAttributes()}Stub (builder inference): ${constructor.variable}" + is ConeStubType -> "${renderAttributes()}Stub (subtyping): ${constructor.variable}" is ConeIntegerLiteralType -> "${renderAttributes()}ILT: $value" } + nullabilitySuffix } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt index 51dda7b3517..3c67444e2cc 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt @@ -127,7 +127,7 @@ fun ConeKotlinType.findClassRepresentation( is ConeTypeParameterType -> lookupTag.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) is ConeTypeVariableType -> (this.lookupTag.originalTypeParameter as? ConeTypeParameterLookupTag) ?.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) - is ConeStubType -> (this.variable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag) + is ConeStubType -> (this.constructor.variable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag) ?.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) is ConeLookupTagBasedType -> null } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 1e48d04f4cf..4429782623f 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -131,7 +131,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo override fun StubTypeMarker.getOriginalTypeVariable(): TypeVariableTypeConstructorMarker { require(this is ConeStubType) - return this.variable.typeConstructor + return this.constructor.variable.typeConstructor } override fun KotlinTypeMarker.typeDepth() = when (this) { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index d2ee6566e29..505fa2a6e18 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -144,7 +144,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty is ConeCapturedType -> constructor is ConeTypeVariableType -> lookupTag is ConeIntersectionType -> this - is ConeStubType -> variable.typeConstructor + is ConeStubType -> constructor is ConeDefinitelyNotNullType -> original.typeConstructor() is ConeIntegerLiteralType -> this else -> error("?: $this") @@ -244,6 +244,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty } } is ConeIntegerLiteralType -> 0 + is ConeStubTypeConstructor -> 0 else -> unknownConstructorError() } } @@ -271,6 +272,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty override fun TypeConstructorMarker.supertypes(): Collection { if (this is ErrorTypeConstructor) return emptyList() return when (this) { + is ConeStubTypeConstructor -> emptyList() is ConeTypeVariableTypeConstructor -> emptyList() is ConeTypeParameterLookupTag -> symbol.fir.bounds.map { it.coneType } is ConeClassLikeLookupTag -> { @@ -342,6 +344,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty is ConeClassLikeLookupTag, is ConeTypeParameterLookupTag -> true + is ConeStubTypeConstructor, is ConeCapturedTypeConstructor, is ErrorTypeConstructor, is ConeTypeVariableTypeConstructor, diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index a22119c3631..a9267885004 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -165,8 +165,8 @@ fun T.withNullability( ConeNullability.UNKNOWN -> this // TODO: is that correct? ConeNullability.NOT_NULL -> this } - is ConeStubTypeForBuilderInference -> ConeStubTypeForBuilderInference(variable, nullability) - is ConeStubTypeForTypeVariableInSubtyping -> ConeStubTypeForTypeVariableInSubtyping(variable, nullability) + is ConeStubTypeForBuilderInference -> ConeStubTypeForBuilderInference(constructor.variable, nullability) + is ConeStubTypeForTypeVariableInSubtyping -> ConeStubTypeForTypeVariableInSubtyping(constructor.variable, nullability) is ConeDefinitelyNotNullType -> when (nullability) { ConeNullability.NOT_NULL -> this ConeNullability.NULLABLE -> original.withNullability(nullability, typeContext) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt index f58adbb2e94..5e24bc3ba84 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt @@ -169,7 +169,7 @@ class FirBuilderInferenceSession( val bindings = mutableMapOf() for ((variable, nonFixedType) in stubsForPostponedVariables) { - bindings[nonFixedType.variable.typeConstructor] = variable.defaultType + bindings[nonFixedType.constructor] = variable.defaultType } return ctx.typeSubstitutorByTypeConstructor(bindings) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeKotlinTypeComparator.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeKotlinTypeComparator.kt index c8df69e13dd..2388f649dc9 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeKotlinTypeComparator.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeKotlinTypeComparator.kt @@ -145,7 +145,7 @@ object ConeKotlinTypeComparator : Comparator { require(b is ConeStubType) { "priority is inconsistent: ${a.render()} v.s. ${b.render()}" } - val nameDiff = a.variable.typeConstructor.name.compareTo(b.variable.typeConstructor.name) + val nameDiff = a.constructor.variable.typeConstructor.name.compareTo(b.constructor.variable.typeConstructor.name) if (nameDiff != 0) { return nameDiff } diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/RenderingForDebugInfo.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/RenderingForDebugInfo.kt index a5af3a51314..09079cc1f89 100644 --- a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/RenderingForDebugInfo.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/RenderingForDebugInfo.kt @@ -39,7 +39,7 @@ fun ConeKotlinType.renderForDebugInfo(): String { separator = " & ", ) { it.renderForDebugInfo() } } - is ConeStubType -> "Stub: $variable" + is ConeStubType -> "Stub: ${constructor.variable}" is ConeIntegerLiteralType -> "ILT: $value" } + nullabilitySuffix }