[NI] Make subtyping algorithm more robust to error types
During subtyping/incorporation we transform types (e.g. changing nullability, form of the type) and, basically, we're doing this to some FIXPOINT. It's important that we use `KotlinType.hashCode()` to compare types, but for error types hashCode is a hashCode of its supertype and, for example, `makeNullableAsSpecified` method recreate type every time. So, we continue to generate new constraints and we'll never stop incorporation algorithm
This commit is contained in:
+5
@@ -154,6 +154,11 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val
|
||||
?: error("Should by type variableConstructor: $typeVariableConstructor. ${c.allTypeVariables.values}")
|
||||
|
||||
var targetType = type
|
||||
if (targetType.isError) {
|
||||
c.addError(ConstrainingTypeIsError(typeVariable, targetType, position))
|
||||
return
|
||||
}
|
||||
|
||||
if (type.contains(this::isCapturedTypeFromSubtyping)) {
|
||||
// TypeVariable <: type -> if TypeVariable <: subType => TypeVariable <: type
|
||||
if (kind == UPPER) {
|
||||
|
||||
+7
-1
@@ -92,4 +92,10 @@ class CapturedTypeFromSubtyping(
|
||||
val position: ConstraintPosition
|
||||
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||
|
||||
class NotEnoughInformationForTypeParameter(val typeVariable: NewTypeVariable) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||
class NotEnoughInformationForTypeParameter(val typeVariable: NewTypeVariable) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||
|
||||
class ConstrainingTypeIsError(
|
||||
val typeVariable: NewTypeVariable,
|
||||
val constraintType: UnwrappedType,
|
||||
val position: IncorporationConstraintPosition
|
||||
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||
Reference in New Issue
Block a user