Skip to content

Commit 53d802a

Browse files
committed
Sema: Re-organize BindingSet::finalize()
1 parent 5f2db0c commit 53d802a

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -665,43 +665,46 @@ static Type getKeyPathType(ASTContext &ctx, KeyPathCapability capability,
665665
}
666666

667667
bool BindingSet::finalize(bool transitive) {
668-
if (transitive)
668+
if (transitive) {
669669
inferTransitiveBindings();
670670

671-
if (auto *locator = TypeVar->getImpl().getLocator()) {
672-
if (locator->isLastElement<LocatorPathElt::MemberRefBase>()) {
673-
// If this is a base of an unresolved member chain, as a last
674-
// resort effort let's infer base to be a protocol type based
675-
// on contextual conformance requirements.
676-
//
677-
// This allows us to find solutions in cases like this:
678-
//
679-
// \code
680-
// func foo<T: P>(_: T) {}
681-
// foo(.bar) <- `.bar` should be a static member of `P`.
682-
// \endcode
683-
if (transitive && !hasViableBindings()) {
684-
inferTransitiveProtocolRequirements();
685-
686-
if (TransitiveProtocols.has_value()) {
687-
for (auto *constraint : *TransitiveProtocols) {
688-
Type protocolTy = constraint->getSecondType();
689-
690-
// Compiler-known marker protocols cannot be extended with members,
691-
// so do not consider them.
692-
if (auto p = protocolTy->getAs<ProtocolType>()) {
693-
if (ProtocolDecl *decl = p->getDecl())
694-
if (decl->getKnownProtocolKind() && decl->isMarkerProtocol())
695-
continue;
696-
}
671+
if (!hasViableBindings()) {
672+
if (auto *locator = TypeVar->getImpl().getLocator()) {
673+
if (locator->isLastElement<LocatorPathElt::MemberRefBase>()) {
674+
// If this is a base of an unresolved member chain, as a last
675+
// resort effort let's infer base to be a protocol type based
676+
// on contextual conformance requirements.
677+
//
678+
// This allows us to find solutions in cases like this:
679+
//
680+
// \code
681+
// func foo<T: P>(_: T) {}
682+
// foo(.bar) <- `.bar` should be a static member of `P`.
683+
// \endcode
684+
inferTransitiveProtocolRequirements();
685+
686+
if (TransitiveProtocols.has_value()) {
687+
for (auto *constraint : *TransitiveProtocols) {
688+
Type protocolTy = constraint->getSecondType();
689+
690+
// Compiler-known marker protocols cannot be extended with members,
691+
// so do not consider them.
692+
if (auto p = protocolTy->getAs<ProtocolType>()) {
693+
if (ProtocolDecl *decl = p->getDecl())
694+
if (decl->getKnownProtocolKind() && decl->isMarkerProtocol())
695+
continue;
696+
}
697697

698-
addBinding({protocolTy, AllowedBindingKind::Exact, constraint},
699-
/*isTransitive=*/false);
698+
addBinding({protocolTy, AllowedBindingKind::Exact, constraint},
699+
/*isTransitive=*/false);
700+
}
700701
}
701702
}
702703
}
703704
}
705+
}
704706

707+
if (auto *locator = TypeVar->getImpl().getLocator()) {
705708
if (TypeVar->getImpl().isKeyPathType()) {
706709
auto &ctx = CS.getASTContext();
707710

0 commit comments

Comments
 (0)