mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain contextual ranking of the type variables associated with them when it comes to picking bindings, otherwise it might lead to no or invalid solutions, because only a set of the bindings for the best type variable is attempted. Resolves: rdar://problem/22898292
This commit is contained in:
@@ -1695,13 +1695,14 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
}
|
||||
|
||||
// If we have a binding for the right-hand side
|
||||
// (argument type) don't try to bind it to the left-hand
|
||||
// side (parameter type) directly, because their
|
||||
// relationship is contravariant and the actual
|
||||
// binding can only come from the left-hand side.
|
||||
// (argument type used in the body) don't try
|
||||
// to bind it to the left-hand side (parameter type)
|
||||
// directly, because there could be an implicit
|
||||
// conversion between them, and actual binding
|
||||
// can only come from the left-hand side.
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::ArgumentConversion, type2,
|
||||
typeVar1, getConstraintLocator(locator)));
|
||||
Constraint::create(*this, ConstraintKind::Equal, typeVar1, type2,
|
||||
getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user