File tree Expand file tree Collapse file tree 2 files changed +18
-17
lines changed
Expand file tree Collapse file tree 2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change @@ -566,21 +566,6 @@ void ConstraintSystem::PotentialBindings::finalize(
566566
567567 addPotentialBinding (PotentialBinding::forHole (TypeVar, locator));
568568 }
569-
570- // Let's always consider `Any` to be a last resort binding because
571- // it's always better to infer concrete type and erase it if required
572- // by the context.
573- if (Bindings.size () > 1 ) {
574- auto AnyTypePos =
575- llvm::find_if (Bindings, [](const PotentialBinding &binding) {
576- return binding.BindingType ->isAny () &&
577- !binding.isDefaultableBinding ();
578- });
579-
580- if (AnyTypePos != Bindings.end ()) {
581- std::rotate (AnyTypePos, AnyTypePos + 1 , Bindings.end ());
582- }
583- }
584569}
585570
586571Optional<ConstraintSystem::PotentialBindings>
Original file line number Diff line number Diff line change @@ -5366,14 +5366,30 @@ TypeVarBindingProducer::TypeVarBindingProducer(
53665366 return false ;
53675367 };
53685368
5369+ // A binding to `Any` which should always be considered as a last resort.
5370+ Optional<Binding> Any;
5371+
53695372 for (const auto &binding : bindings.Bindings ) {
5373+ auto type = binding.BindingType ;
5374+
5375+ if (!CanBeNil && type->isAny ()) {
5376+ Any.emplace (binding);
5377+ continue ;
5378+ }
5379+
53705380 // Adjust optionality of existing bindings based on presence of
53715381 // `ExpressibleByNilLiteral` requirement.
53725382 if (CanBeNil && requiresOptionalAdjustment (binding)) {
5373- Bindings.push_back (
5374- binding.withType (OptionalType::get (binding.BindingType )));
5383+ Bindings.push_back (binding.withType (OptionalType::get (type)));
53755384 } else {
53765385 Bindings.push_back (binding);
53775386 }
53785387 }
5388+
5389+ // Let's always consider `Any` to be a last resort binding because
5390+ // it's always better to infer concrete type and erase it if required
5391+ // by the context.
5392+ if (Any) {
5393+ Bindings.push_back (*Any);
5394+ }
53795395}
You can’t perform that action at this time.
0 commit comments