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 3b3ba62197a..94139a782ed 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)) } -data class ConeStubTypeConstructor(val variable: ConeTypeVariable, val isTypeVariableInSubtyping: Boolean) : TypeConstructorMarker +data class ConeStubTypeConstructor( + val variable: ConeTypeVariable, + val isTypeVariableInSubtyping: Boolean, + val isForFixation: Boolean = false, +) : TypeConstructorMarker sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker, ConeSimpleKotlinType() { @@ -363,6 +367,9 @@ open class ConeStubTypeForBuilderInference(constructor: ConeStubTypeConstructor, ) } +class ConeStubTypeForFixation(constructor: ConeStubTypeConstructor, nullability: ConeNullability) : + ConeStubTypeForBuilderInference(constructor, nullability) + class ConeStubTypeForTypeVariableInSubtyping(constructor: ConeStubTypeConstructor, nullability: ConeNullability) : ConeStubType(constructor, nullability) { constructor(variable: ConeTypeVariable, nullability: ConeNullability) : 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 a4d6b4722f3..4fbbd85f769 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 @@ -435,6 +435,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty override fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker { if (this !is ConeStubTypeConstructor) return this if (this.isTypeVariableInSubtyping) return this + if (this.isForFixation) return this return this.variable.typeConstructor } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index c640acd1781..b425be8bf73 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -226,15 +226,21 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents, p val variableWithConstraints = notFixedTypeVariables.getValue(variableForFixation.variable) - if (variableForFixation.hasProperConstraint) { - fixVariable(asConstraintSystemCompletionContext(), topLevelType, variableWithConstraints, postponedArguments) - return true - } else if (context.inferenceSession.isSyntheticTypeVariable(variableWithConstraints.typeVariable)) { - val variable = variableWithConstraints.typeVariable as ConeTypeVariable - context.inferenceSession.fixSyntheticTypeVariableWithNotEnoughInformation(variable, asConstraintSystemCompletionContext()) - return true - } else { - processVariableWhenNotEnoughInformation(this, variableWithConstraints, topLevelAtoms) + when { + variableForFixation.hasProperConstraint -> { + fixVariable(asConstraintSystemCompletionContext(), topLevelType, variableWithConstraints, postponedArguments) + return true + } + context.inferenceSession.isSyntheticTypeVariable(variableWithConstraints.typeVariable) -> { + context.inferenceSession.fixSyntheticTypeVariableWithNotEnoughInformation( + variableWithConstraints.typeVariable as ConeTypeVariable, + asConstraintSystemCompletionContext() + ) + return true + } + else -> { + processVariableWhenNotEnoughInformation(this, variableWithConstraints, topLevelAtoms) + } } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt index 1dbde44296c..1c2d93e6884 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt @@ -112,15 +112,16 @@ class FirDelegatedPropertyInferenceSession( private fun createNonFixedTypeToVariableSubstitutor(): ConeSubstitutor { val typeContext = components.session.typeContext - val bindings = mutableMapOf() - for ((variable, stubType) in stubTypesByTypeVariable) { - bindings[stubType.constructor] = variable.defaultType(typeContext) as ConeKotlinType + val bindings = mutableMapOf() + for ((variable, synthetic) in syntheticTypeVariableByTypeVariable) { + bindings[synthetic] = variable.defaultType(typeContext) as ConeKotlinType } return object : AbstractConeSubstitutor(typeContext) { override fun substituteType(type: ConeKotlinType): ConeKotlinType? { if (type !is ConeStubType) return null - return bindings[type.constructor].updateNullabilityIfNeeded(type) + if (type.constructor.isTypeVariableInSubtyping) return null + return bindings[type.constructor.variable].updateNullabilityIfNeeded(type) } } } @@ -151,9 +152,13 @@ class FirDelegatedPropertyInferenceSession( typeVariable: TypeVariableMarker, completionContext: ConstraintSystemCompletionContext ) { + typeVariable as ConeTypeVariable completionContext.fixVariable( typeVariable, - stubTypeBySyntheticTypeVariable[typeVariable]!!, + ConeStubTypeForFixation( + ConeStubTypeConstructor(typeVariable, isTypeVariableInSubtyping = false, isForFixation = true), + ConeNullability.create(typeVariable.defaultType.isMarkedNullable) + ), ConeFixVariableConstraintPosition(typeVariable) ) }