RequirementMachine: Introduce conditional requirements in desugaring

This commit is contained in:
Slava Pestov
2022-02-10 17:02:28 -05:00
parent 48ca87ddeb
commit d64fb39514
2 changed files with 31 additions and 3 deletions

View File

@@ -136,7 +136,23 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
// Fast path.
if (constraintType->is<ProtocolType>()) {
if (!subjectType->isTypeParameter()) {
// FIXME: Check conformance, diagnose redundancy or conflict upstream
// Check if the subject type actually conforms.
auto *protoDecl = constraintType->castTo<ProtocolType>()->getDecl();
auto *module = protoDecl->getParentModule();
auto conformance = module->lookupConformance(subjectType, protoDecl);
if (conformance.isInvalid()) {
// FIXME: Diagnose a conflict.
return;
}
// FIXME: Diagnose a redundancy.
assert(conformance.isConcrete());
auto *concrete = conformance.getConcrete();
// Introduce conditional requirements if the subject type is concrete.
for (auto req : concrete->getConditionalRequirements()) {
desugarRequirement(req, result);
}
return;
}