FIR: Fix synthetic type variables to independent stub types
This commit is contained in:
committed by
teamcity
parent
580410863f
commit
df9da371cb
@@ -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(
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+15
-9
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -112,15 +112,16 @@ class FirDelegatedPropertyInferenceSession(
|
||||
private fun createNonFixedTypeToVariableSubstitutor(): ConeSubstitutor {
|
||||
val typeContext = components.session.typeContext
|
||||
|
||||
val bindings = mutableMapOf<TypeConstructorMarker, ConeKotlinType>()
|
||||
for ((variable, stubType) in stubTypesByTypeVariable) {
|
||||
bindings[stubType.constructor] = variable.defaultType(typeContext) as ConeKotlinType
|
||||
val bindings = mutableMapOf<TypeVariableMarker, ConeKotlinType>()
|
||||
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)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user