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 505fa2a6e18..056b59ec745 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 @@ -432,6 +432,12 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty return this is ConeStubTypeForBuilderInference } + override fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker { + if (this !is ConeStubTypeConstructor) return this + if (this.isTypeVariableInSubtyping) return this + return this.variable.typeConstructor + } + override fun intersectTypes(types: List): SimpleTypeMarker { @Suppress("UNCHECKED_CAST") return ConeTypeIntersector.intersectTypes(this as ConeInferenceContext, types as List) as SimpleTypeMarker diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index 36bd20cee84..d78135e0a26 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -47,6 +47,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon override fun SimpleTypeMarker.isStubTypeForBuilderInference() = false + override fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker = this + override fun FlexibleTypeMarker.asDynamicType() = this as? IrDynamicType override fun FlexibleTypeMarker.asRawType(): RawTypeMarker? = null diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index bbc18fa8351..27123ca016f 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -293,7 +293,7 @@ class ConstraintInjector( // from AbstractTypeCheckerContextForConstraintSystem override fun isMyTypeVariable(type: SimpleTypeMarker): Boolean = - c.allTypeVariables.containsKey(type.typeConstructor()) + c.allTypeVariables.containsKey(type.typeConstructor().unwrapStubTypeVariableConstructor()) override fun addUpperConstraint(typeVariable: TypeConstructorMarker, superType: KotlinTypeMarker) = addConstraint(typeVariable, superType, UPPER) @@ -326,7 +326,7 @@ class ConstraintInjector( kind: ConstraintKind, isFromNullabilityConstraint: Boolean = false ) { - val typeVariable = c.allTypeVariables[typeVariableConstructor] + val typeVariable = c.allTypeVariables[typeVariableConstructor.unwrapStubTypeVariableConstructor()] ?: error("Should by type variableConstructor: $typeVariableConstructor. ${c.allTypeVariables.values}") addNewIncorporatedConstraint( diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index a81df4eb87f..4c14d266c8a 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -358,6 +358,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext { fun SimpleTypeMarker.isStubType(): Boolean fun SimpleTypeMarker.isStubTypeForVariableInSubtyping(): Boolean fun SimpleTypeMarker.isStubTypeForBuilderInference(): Boolean + fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker fun KotlinTypeMarker.asTypeArgument(): TypeArgumentMarker diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index 61bd854b362..04064096b24 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -100,6 +100,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy return this is StubTypeForBuilderInference || isDefNotNullStubType() } + override fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker { + return this + } + override fun StubTypeMarker.getOriginalTypeVariable(): TypeVariableTypeConstructorMarker { require(this is AbstractStubType, this::errorMessage) return this.originalTypeVariable as TypeVariableTypeConstructorMarker