Skip to content

Commit 12cb368

Browse files
committed
IDE: invertible protocols have no members
We can avoid lookup entirely on invertible protocols because they never can have any members. This saves us from having to update tests and perhaps some extra work in code completion.
1 parent da8de56 commit 12cb368

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ static void lookupTypeMembers(Type BaseType, NominalTypeDecl *LookupType,
271271
assert(!BaseType->hasTypeParameter());
272272
assert(LookupType && "should have a nominal type");
273273

274+
// Skip lookup on invertible protocols. They have no members.
275+
if (auto *proto = dyn_cast<ProtocolDecl>(LookupType))
276+
if (proto->getInvertibleProtocolKind())
277+
return;
278+
274279
Consumer.onLookupNominalTypeMembers(LookupType, Reason);
275280

276281
SmallVector<ValueDecl*, 2> FoundDecls;
@@ -444,6 +449,10 @@ static void lookupDeclsFromProtocolsBeingConformedTo(
444449

445450
for (auto Conformance : CurrNominal->getAllConformances()) {
446451
auto Proto = Conformance->getProtocol();
452+
// Skip conformances to invertible protocols. They have no members.
453+
if (Proto->getInvertibleProtocolKind())
454+
continue;
455+
447456
if (!Proto->isAccessibleFrom(FromContext))
448457
continue;
449458

0 commit comments

Comments
 (0)