Skip to content

Commit 09d665d

Browse files
committed
Drop the DeclContext parameter from TypeChecker::checkInheritanceClause().
The declaration whose inheritance clause is being checked has enough information to figure this out. Callers will just screw it up anyway. Swift SVN r26653
1 parent 59926f1 commit 09d665d

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

lib/Sema/TypeCheckDecl.cpp

+20-7
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,32 @@ void TypeChecker::resolveInheritanceClause(DeclContext *dc) {
293293
/// This routine validates all of the types in the parsed inheritance clause,
294294
/// recording the superclass (if any and if allowed) as well as the protocols
295295
/// to which this type declaration conforms.
296-
void TypeChecker::checkInheritanceClause(Decl *decl, DeclContext *DC,
296+
void TypeChecker::checkInheritanceClause(Decl *decl,
297297
GenericTypeResolver *resolver) {
298298
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)) {
301311
DC = nominal;
302312
options |= TR_NominalInheritanceClause;
303-
} else if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
313+
} else if (auto ext = dyn_cast<ExtensionDecl>(DC)) {
304314
DC = ext;
305315
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();
308319
}
320+
} else {
321+
DC = decl->getDeclContext();
309322
}
310323

311324
// Establish a default generic type resolver.
@@ -840,7 +853,7 @@ static void checkGenericParamList(ArchetypeBuilder &builder,
840853
GP->setDepth(Depth);
841854

842855
// Check the constraints on the type parameter.
843-
TC.checkInheritanceClause(GP, DC);
856+
TC.checkInheritanceClause(GP);
844857

845858
// Add the generic parameter to the builder.
846859
builder.addGenericParameter(GP);

lib/Sema/TypeCheckGeneric.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static bool checkGenericParameters(TypeChecker &tc, ArchetypeBuilder *builder,
232232
param->setDepth(depth);
233233

234234
// Check the inheritance clause of this type parameter.
235-
tc.checkInheritanceClause(param, parentDC, &resolver);
235+
tc.checkInheritanceClause(param, &resolver);
236236

237237
if (builder) {
238238
// Add the generic parameter to the builder.

lib/Sema/TypeChecker.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ class TypeChecker final : public LazyResolver {
735735
void resolveInheritanceClause(DeclContext *dc) override;
736736

737737
/// Check the inheritance clause of the given declaration.
738-
void checkInheritanceClause(Decl *decl, DeclContext *DC = nullptr,
738+
void checkInheritanceClause(Decl *decl,
739739
GenericTypeResolver *resolver = nullptr);
740740

741741
/// Retrieve the set of protocols to which this nominal type declaration

0 commit comments

Comments
 (0)