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(
566
566
567
567
addPotentialBinding (PotentialBinding::forHole (TypeVar, locator));
568
568
}
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
- }
584
569
}
585
570
586
571
Optional<ConstraintSystem::PotentialBindings>
Original file line number Diff line number Diff line change @@ -5366,14 +5366,30 @@ TypeVarBindingProducer::TypeVarBindingProducer(
5366
5366
return false ;
5367
5367
};
5368
5368
5369
+ // A binding to `Any` which should always be considered as a last resort.
5370
+ Optional<Binding> Any;
5371
+
5369
5372
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
+
5370
5380
// Adjust optionality of existing bindings based on presence of
5371
5381
// `ExpressibleByNilLiteral` requirement.
5372
5382
if (CanBeNil && requiresOptionalAdjustment (binding)) {
5373
- Bindings.push_back (
5374
- binding.withType (OptionalType::get (binding.BindingType )));
5383
+ Bindings.push_back (binding.withType (OptionalType::get (type)));
5375
5384
} else {
5376
5385
Bindings.push_back (binding);
5377
5386
}
5378
5387
}
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
+ }
5379
5395
}
You can’t perform that action at this time.
0 commit comments