Skip to content

Commit aae6e0c

Browse files
committed
[CSBindings] Let's always consider Any to be a last resort binding
If `Any` has been inferred as a non-default binding (e.g. if parameter has `Any` type) let's give it the lowest priority and attempt after any other bindings (including literal ones) because it's better to infer some concrete type and then erase it to `Any` if required by the constraint system.
1 parent 1b75bd0 commit aae6e0c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,19 @@ void ConstraintSystem::PotentialBindings::finalize(
289289
addPotentialBinding(PotentialBinding::forHole(cs.getASTContext(), locator));
290290
}
291291

292+
// Let's always consider `Any` to be a last resort binding because
293+
// it's always better to infer concrete type and erase it if required
294+
// by the context.
295+
if (Bindings.size() > 1) {
296+
auto anyType = llvm::find_if(Bindings, [](const PotentialBinding &binding) {
297+
return binding.BindingType->isAny() && !binding.isDefaultableBinding();
298+
});
299+
300+
if (anyType != Bindings.end()) {
301+
std::rotate(Bindings.begin(), anyType + 1, Bindings.end());
302+
}
303+
}
304+
292305
// Determine if the bindings only constrain the type variable from above with
293306
// an existential type; such a binding is not very helpful because it's
294307
// impossible to enumerate the existential type's subtypes.

0 commit comments

Comments
 (0)