@@ -481,7 +481,7 @@ void ConstraintSystem::PotentialBindings::inferDefaultTypes(
481
481
break ;
482
482
483
483
// If this literal protocol is not a direct requirement it
484
- // would be possible to change optionality while inferring
484
+ // would not be possible to change optionality while inferring
485
485
// bindings for a supertype, so this hack doesn't apply.
486
486
if (!isDirectRequirement)
487
487
break ;
@@ -506,17 +506,22 @@ void ConstraintSystem::PotentialBindings::inferDefaultTypes(
506
506
binding.BindingType = type;
507
507
}
508
508
509
- // If this is not a literal protocol or it has been "covered" by an existing
510
- // binding it can't provide a default type.
511
- auto isUnviableForDefaulting = [&literalProtocols](ProtocolDecl *protocol) {
512
- auto literal = literalProtocols.find (protocol);
513
- return literal == literalProtocols.end () || literal->second .second ;
514
- };
515
-
516
509
for (auto *constraint : Protocols) {
517
510
auto *protocol = constraint->getProtocol ();
518
511
519
- if (isUnviableForDefaulting (protocol))
512
+ auto literal = literalProtocols.find (protocol);
513
+ if (literal == literalProtocols.end ())
514
+ continue ;
515
+
516
+ bool isDirectRequirement = false ;
517
+ bool isCovered = false ;
518
+
519
+ std::tie (isDirectRequirement, isCovered) = literal->second ;
520
+
521
+ // Can't be defaulted because it's already covered by an
522
+ // existing direct or transitive binding which is always
523
+ // better.
524
+ if (isCovered)
520
525
continue ;
521
526
522
527
auto defaultType = TypeChecker::getDefaultType (protocol, cs.DC );
@@ -530,9 +535,8 @@ void ConstraintSystem::PotentialBindings::inferDefaultTypes(
530
535
// requirement or inferred transitive one to identify binding
531
536
// kind correctly.
532
537
addPotentialBinding ({defaultType,
533
- isDirectRequirement (constraint)
534
- ? AllowedBindingKind::Subtypes
535
- : AllowedBindingKind::Supertypes,
538
+ isDirectRequirement ? AllowedBindingKind::Subtypes
539
+ : AllowedBindingKind::Supertypes,
536
540
constraint});
537
541
}
538
542
}
0 commit comments