Skip to content

Commit 7f75914

Browse files
committed
[GSB] Make requirement-signature computation more robust for nested protocols.
Add all of the generic parameters from outer contexts as well. This only occurs in ill-formed code, but maintains a GenericSignatureBuilder invariant that it knows about all of the generic parameters in play.
1 parent ac79fa2 commit 7f75914

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7491,6 +7491,17 @@ GenericSignature *GenericSignatureBuilder::computeGenericSignature(
74917491
return sig;
74927492
}
74937493

7494+
/// Add all of the generic parameters from the given parameter list (and it's
7495+
/// outer generic parameter lists) to the given generic signature builder.
7496+
static void addAllGenericParams(GenericSignatureBuilder &builder,
7497+
GenericParamList *genericParams) {
7498+
if (!genericParams) return;
7499+
7500+
addAllGenericParams(builder, genericParams->getOuterParameters());
7501+
for (auto gp : *genericParams)
7502+
builder.addGenericParameter(gp);
7503+
}
7504+
74947505
GenericSignature *GenericSignatureBuilder::computeRequirementSignature(
74957506
ProtocolDecl *proto) {
74967507
GenericSignatureBuilder builder(proto->getASTContext());
@@ -7501,12 +7512,12 @@ GenericSignature *GenericSignatureBuilder::computeRequirementSignature(
75017512
lazyResolver->resolveDeclSignature(proto);
75027513
}
75037514

7504-
// Add the 'self' parameter.
7505-
auto selfType =
7506-
proto->getSelfInterfaceType()->castTo<GenericTypeParamType>();
7507-
builder.addGenericParameter(selfType);
7515+
// Add all of the generic parameters.
7516+
addAllGenericParams(builder, proto->getGenericParams());
75087517

75097518
// Add the conformance of 'self' to the protocol.
7519+
auto selfType =
7520+
proto->getSelfInterfaceType()->castTo<GenericTypeParamType>();
75107521
auto requirement =
75117522
Requirement(RequirementKind::Conformance, selfType,
75127523
proto->getDeclaredInterfaceType());

0 commit comments

Comments
 (0)