@@ -293,19 +293,32 @@ void TypeChecker::resolveInheritanceClause(DeclContext *dc) {
293
293
// / This routine validates all of the types in the parsed inheritance clause,
294
294
// / recording the superclass (if any and if allowed) as well as the protocols
295
295
// / to which this type declaration conforms.
296
- void TypeChecker::checkInheritanceClause (Decl *decl, DeclContext *DC,
296
+ void TypeChecker::checkInheritanceClause (Decl *decl,
297
297
GenericTypeResolver *resolver) {
298
298
TypeResolutionOptions options;
299
- if (!DC) {
300
- if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
299
+ DeclContext *DC;
300
+ if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
301
+ DC = nominal;
302
+ options |= TR_NominalInheritanceClause;
303
+ } else if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
304
+ DC = ext;
305
+ options |= TR_NominalInheritanceClause;
306
+ } else if (isa<GenericTypeParamDecl>(decl)) {
307
+ // For generic parameters, we want name lookup to look at just the
308
+ // signature of the enclosing entity.
309
+ DC = decl->getDeclContext ();
310
+ if (auto nominal = dyn_cast<NominalTypeDecl>(DC)) {
301
311
DC = nominal;
302
312
options |= TR_NominalInheritanceClause;
303
- } else if (auto ext = dyn_cast<ExtensionDecl>(decl )) {
313
+ } else if (auto ext = dyn_cast<ExtensionDecl>(DC )) {
304
314
DC = ext;
305
315
options |= TR_NominalInheritanceClause;
306
- } else {
307
- DC = decl->getDeclContext ();
316
+ } else if (!DC->isModuleScopeContext ()) {
317
+ // Skip the generic parameter's context entirely.
318
+ DC = DC->getParent ();
308
319
}
320
+ } else {
321
+ DC = decl->getDeclContext ();
309
322
}
310
323
311
324
// Establish a default generic type resolver.
@@ -840,7 +853,7 @@ static void checkGenericParamList(ArchetypeBuilder &builder,
840
853
GP->setDepth (Depth);
841
854
842
855
// Check the constraints on the type parameter.
843
- TC.checkInheritanceClause (GP, DC );
856
+ TC.checkInheritanceClause (GP);
844
857
845
858
// Add the generic parameter to the builder.
846
859
builder.addGenericParameter (GP);
0 commit comments