Make LookupConformanceFn callbacks return Optional<ProtocolConformanceRef>.

NFC yet, but this is a step toward centralizing error handling policy for failed conformance lookups instead of leaving it ad-hoc.
This commit is contained in:
Joe Groff
2016-12-14 18:04:35 -08:00
parent 55bdf5954c
commit ccfabd1118
5 changed files with 38 additions and 37 deletions

View File

@@ -628,24 +628,25 @@ TypeBase::gatherAllSubstitutions(Module *module,
auto lookupConformanceFn =
[&](CanType original, Type replacement, ProtocolType *protoType)
-> ProtocolConformanceRef {
auto *proto = protoType->getDecl();
// If the type is a type variable or is dependent, just fill in empty
// conformances.
if (replacement->isTypeVariableOrMember() ||
replacement->isTypeParameter())
return ProtocolConformanceRef(proto);
// Otherwise, find the conformance.
auto conforms = module->lookupConformance(replacement, proto, resolver);
if (conforms)
return *conforms;
// FIXME: Should we ever end up here?
return ProtocolConformanceRef(proto);
};
-> Optional<ProtocolConformanceRef> {
auto *proto = protoType->getDecl();
// If the type is a type variable or is dependent, just fill in empty
// conformances.
if (replacement->isTypeVariableOrMember() ||
replacement->isTypeParameter())
return ProtocolConformanceRef(proto);
// Otherwise, try to find the conformance.
auto conforms = module->lookupConformance(replacement, proto, resolver);
if (conforms)
return *conforms;
// FIXME: Should we ever end up here?
// We should return None and let getSubstitutions handle the error
// if we do.
return ProtocolConformanceRef(proto);
};
SmallVector<Substitution, 4> result;
genericSig->getSubstitutions(*module, substitutions,