Skip to content

Commit bfb252a

Browse files
committed
Sema: Small NFC cleanup for LookupResultBuilder::add()
1 parent f51a9d0 commit bfb252a

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ namespace {
129129

130130
assert(isa<ProtocolDecl>(foundDC));
131131

132+
if (!Options.contains(NameLookupFlags::PerformConformanceCheck))
133+
return;
134+
135+
// If we found something within the protocol itself, and our
136+
// search began somewhere that is not in a protocol or extension
137+
// thereof, remap this declaration to the witness.
132138
auto conformingType = foundInType;
133139

134140
// When performing a lookup on a subclass existential, we might
@@ -143,50 +149,43 @@ namespace {
143149
conformingType = layout.superclass;
144150
}
145151

146-
// If we found something within the protocol itself, and our
147-
// search began somewhere that is not in a protocol or extension
148-
// thereof, remap this declaration to the witness.
149-
if (Options.contains(NameLookupFlags::PerformConformanceCheck)) {
150-
// Dig out the protocol conformance.
151-
auto conformance = TC.conformsToProtocol(conformingType, foundProto, DC,
152+
// Dig out the protocol conformance.
153+
auto conformance = TC.conformsToProtocol(conformingType, foundProto, DC,
152154
conformanceOptions);
153-
if (!conformance) {
154-
// If there's no conformance, we have an existential
155-
// and we found a member from one of the protocols, and
156-
// not a class constraint if any.
157-
assert(foundInType->isExistentialType());
158-
addResult(found);
159-
return;
160-
}
161-
162-
if (conformance->isAbstract()) {
163-
assert(foundInType->is<ArchetypeType>() ||
164-
foundInType->isExistentialType());
165-
addResult(found);
166-
return;
167-
}
168-
169-
// Dig out the witness.
170-
ValueDecl *witness = nullptr;
171-
auto concrete = conformance->getConcrete();
172-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(found)) {
173-
witness = concrete->getTypeWitnessAndDecl(assocType, &TC)
174-
.second;
175-
} else if (found->isProtocolRequirement()) {
176-
witness = concrete->getWitnessDecl(found, &TC);
177-
}
178-
179-
// FIXME: the "isa<ProtocolDecl>()" check will be wrong for
180-
// default implementations in protocols.
181-
//
182-
// If we have an imported conformance or the witness could
183-
// not be deserialized, getWitnessDecl() will just return
184-
// the requirement, so just drop the lookup result here.
185-
if (witness && !isa<ProtocolDecl>(witness->getDeclContext()))
186-
addResult(witness);
155+
if (!conformance) {
156+
// If there's no conformance, we have an existential
157+
// and we found a member from one of the protocols, and
158+
// not a class constraint if any.
159+
assert(foundInType->isExistentialType());
160+
addResult(found);
161+
return;
162+
}
187163

164+
if (conformance->isAbstract()) {
165+
assert(foundInType->is<ArchetypeType>() ||
166+
foundInType->isExistentialType());
167+
addResult(found);
188168
return;
189169
}
170+
171+
// Dig out the witness.
172+
ValueDecl *witness = nullptr;
173+
auto concrete = conformance->getConcrete();
174+
if (auto assocType = dyn_cast<AssociatedTypeDecl>(found)) {
175+
witness = concrete->getTypeWitnessAndDecl(assocType, &TC)
176+
.second;
177+
} else if (found->isProtocolRequirement()) {
178+
witness = concrete->getWitnessDecl(found, &TC);
179+
}
180+
181+
// FIXME: the "isa<ProtocolDecl>()" check will be wrong for
182+
// default implementations in protocols.
183+
//
184+
// If we have an imported conformance or the witness could
185+
// not be deserialized, getWitnessDecl() will just return
186+
// the requirement, so just drop the lookup result here.
187+
if (witness && !isa<ProtocolDecl>(witness->getDeclContext()))
188+
addResult(witness);
190189
}
191190
};
192191
} // end anonymous namespace

0 commit comments

Comments
 (0)