Skip to content

Commit 88654b2

Browse files
committed
[CSBindings] Inferring protocol type for member chain base makes binding potentially incomplete
1 parent 74d2a6c commit 88654b2

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ bool PotentialBindings::isPotentiallyIncomplete() const {
140140
if (!locator)
141141
return false;
142142

143+
if (locator->isLastElement<LocatorPathElt::MemberRefBase>() &&
144+
!Bindings.empty()) {
145+
// If the base of the unresolved member reference like `.foo`
146+
// couldn't be resolved we'd want to bind it to a hole at the
147+
// very last moment possible, just like generic parameters.
148+
if (isHole())
149+
return true;
150+
151+
auto &binding = Bindings.front();
152+
// If base type of a member chain is inferred to be a protocol type,
153+
// let's consider this binding set to be potentially incomplete since
154+
// that's done as a last resort effort at resolving first member.
155+
if (auto *constraint = binding.getSource()) {
156+
if (binding.BindingType->is<ProtocolType>() &&
157+
constraint->getKind() == ConstraintKind::ConformsTo)
158+
return true;
159+
}
160+
}
161+
143162
if (locator->isLastElement<LocatorPathElt::UnresolvedMemberChainResult>()) {
144163
// If subtyping is allowed and this is a result of an implicit member chain,
145164
// let's delay binding it to an optional until its object type resolved too or
@@ -159,12 +178,6 @@ bool PotentialBindings::isPotentiallyIncomplete() const {
159178
}
160179

161180
if (isHole()) {
162-
// If the base of the unresolved member reference like `.foo`
163-
// couldn't be resolved we'd want to bind it to a hole at the
164-
// very last moment possible, just like generic parameters.
165-
if (locator->isLastElement<LocatorPathElt::MemberRefBase>())
166-
return true;
167-
168181
// Delay resolution of the code completion expression until
169182
// the very end to give it a chance to be bound to some
170183
// contextual type even if it's a hole.
@@ -428,7 +441,6 @@ void PotentialBindings::finalize(
428441
{protocolTy, AllowedBindingKind::Exact, constraint});
429442
}
430443

431-
PotentiallyIncomplete = true;
432444
FullyBound = true;
433445
}
434446
}

0 commit comments

Comments
 (0)