Sema: Fix generics invariant violations in override checking

Override checking checks if the derived declaration's generic
signature is compatible with the base, but it does this after
doing a bunch of other checks which feed potentially invalid
type parameters to generic signature queries.

Now that the requirement machine is stricter about this kind
of this, re-organize some code to get around this.

Unfortunately this regresses a diagnostic, because we reject
candidates with mismatched generic requirements earlier in
the process.
This commit is contained in:
Slava Pestov
2021-08-21 00:54:06 -04:00
parent 382f04ac79
commit 7c29aaf3e2
7 changed files with 87 additions and 53 deletions

View File

@@ -541,8 +541,9 @@ computeDesignatedInitOverrideSignature(ASTContext &ctx,
auto lookupConformanceFn =
[&](CanType depTy, Type substTy,
ProtocolDecl *proto) -> ProtocolConformanceRef {
if (auto conf = subMap.lookupConformance(depTy, proto))
return conf;
if (depTy->getRootGenericParam()->getDepth() < superclassDepth)
if (auto conf = subMap.lookupConformance(depTy, proto))
return conf;
return ProtocolConformanceRef(proto);
};
@@ -1125,9 +1126,7 @@ static void addImplicitInheritedConstructorsToClass(ClassDecl *decl) {
continue;
auto type = swift::getMemberTypeForComparison(ctor, nullptr);
auto parentType = swift::getMemberTypeForComparison(superclassCtor, ctor);
if (isOverrideBasedOnType(ctor, type, superclassCtor, parentType)) {
if (isOverrideBasedOnType(ctor, type, superclassCtor)) {
alreadyDeclared = true;
break;
}