@@ -549,28 +549,36 @@ bool ConstraintSystem::PotentialBindings::addPotentialBinding(
549
549
// check whether we can combine it with another
550
550
// supertype binding by computing the 'join' of the types.
551
551
if (binding.isViableForJoin () && allowJoinMeet) {
552
- bool joined = false ;
553
-
554
552
auto isAcceptableJoin = [](Type type) {
555
553
return !type->isAny () && (!type->getOptionalObjectType () ||
556
554
!type->getOptionalObjectType ()->isAny ());
557
555
};
558
556
559
- for (auto &existingBinding : Bindings) {
560
- if (!existingBinding.isViableForJoin ())
561
- continue ;
562
-
563
- auto join = Type::join (existingBinding.BindingType , binding.BindingType );
564
-
565
- if (join && isAcceptableJoin (*join)) {
566
- existingBinding.BindingType = *join;
567
- joined = true ;
557
+ SmallVector<PotentialBinding, 4 > joined;
558
+ for (auto existingBinding = Bindings.begin ();
559
+ existingBinding != Bindings.end ();) {
560
+ if (existingBinding->isViableForJoin ()) {
561
+ auto join =
562
+ Type::join (existingBinding->BindingType , binding.BindingType );
563
+
564
+ if (join && isAcceptableJoin (*join)) {
565
+ joined.push_back (existingBinding->withType (*join));
566
+ // Remove existing binding from the set.
567
+ // It has to be re-introduced later, since its type has been changed.
568
+ existingBinding = Bindings.erase (existingBinding);
569
+ continue ;
570
+ }
568
571
}
572
+
573
+ ++existingBinding;
569
574
}
570
575
576
+ for (const auto &binding : joined)
577
+ (void )Bindings.insert (binding);
578
+
571
579
// If new binding has been joined with at least one of existing
572
580
// bindings, there is no reason to include it into the set.
573
- if (joined)
581
+ if (! joined. empty () )
574
582
return false ;
575
583
}
576
584
0 commit comments