[AST] Allow computation of erroneous substitutions.

Be more tolerant of substitutions for erroneous types; the type
checker will diagnose these issues, but later code paths might still
form these substititions. Put in error types rather than crashing.
This commit is contained in:
Doug Gregor
2017-01-19 10:43:24 -08:00
parent d947ed33c0
commit e305b2017b

View File

@@ -389,10 +389,16 @@ getSubstitutions(TypeSubstitutionFn subs,
for (auto req: reqs) {
assert(req.getKind() == RequirementKind::Conformance);
auto protoType = req.getSecondType()->castTo<ProtocolType>();
// TODO: Error handling for failed conformance lookup.
currentConformances.push_back(
*lookupConformance(depTy->getCanonicalType(), currentReplacement,
protoType));
if (auto conformance = lookupConformance(depTy->getCanonicalType(),
currentReplacement,
protoType)) {
currentConformances.push_back(*conformance);
} else {
if (!currentReplacement->hasError())
currentReplacement = ErrorType::get(currentReplacement);
currentConformances.push_back(
ProtocolConformanceRef(protoType->getDecl()));
}
}
// Add it to the final substitution list.