Skip to content

Commit 2100278

Browse files
committed
Sema: Move a diagnostic from bindExtensionToNominal() to typeCheckDecl()
1 parent 1ca81c4 commit 2100278

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,6 +2963,17 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29632963
if (enumDecl->hasRawType())
29642964
checkEnumRawValues(TC, enumDecl);
29652965
}
2966+
2967+
// Only generic and protocol types are permitted to have
2968+
// trailing where clauses.
2969+
if (auto trailingWhereClause = ED->getTrailingWhereClause()) {
2970+
if (!ED->getGenericParams() &&
2971+
!ED->isInvalid()) {
2972+
ED->diagnose(diag::extension_nongeneric_trailing_where,
2973+
nominal->getFullName())
2974+
.highlight(trailingWhereClause->getSourceRange());
2975+
}
2976+
}
29662977
}
29672978

29682979
if (auto genericParams = ED->getGenericParams())

lib/Sema/TypeChecker.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,7 @@ static void bindExtensionToNominal(ExtensionDecl *ext,
348348
// If we have a trailing where clause, deal with it now.
349349
// For now, trailing where clauses are only permitted on protocol extensions.
350350
if (auto trailingWhereClause = ext->getTrailingWhereClause()) {
351-
if (!genericParams) {
352-
// Only generic and protocol types are permitted to have
353-
// trailing where clauses.
354-
ext->diagnose(diag::extension_nongeneric_trailing_where,
355-
nominal->getFullName())
356-
.highlight(trailingWhereClause->getSourceRange());
357-
ext->setTrailingWhereClause(nullptr);
358-
} else {
351+
if (genericParams) {
359352
// Merge the trailing where clause into the generic parameter list.
360353
// FIXME: Long-term, we'd like clients to deal with the trailing where
361354
// clause explicitly, but for now it's far more direct to represent
@@ -365,6 +358,9 @@ static void bindExtensionToNominal(ExtensionDecl *ext,
365358
trailingWhereClause->getWhereLoc(),
366359
trailingWhereClause->getRequirements());
367360
}
361+
362+
// If there's no generic parameter list, the where clause is diagnosed
363+
// in typeCheckDecl().
368364
}
369365

370366
nominal->addExtension(ext);

0 commit comments

Comments
 (0)