Skip to content

Commit b40d807

Browse files
committed
Sema: Allow parametrized protocol types in protocol inheritance clauses
And ban them in other inheritance clauses.
1 parent ef77e6c commit b40d807

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,8 @@ ERROR(inheritance_from_non_protocol_or_class,none,
27732773
"inheritance from non-protocol, non-class type %0", (Type))
27742774
ERROR(inheritance_from_non_protocol,none,
27752775
"inheritance from non-protocol type %0", (Type))
2776+
ERROR(inheritance_from_parametrized_protocol,none,
2777+
"cannot inherit from parametrized protocol type %0", (Type))
27762778
ERROR(superclass_not_first,none,
27772779
"superclass %0 must appear first in the inheritance clause", (Type))
27782780
ERROR(superclass_not_open,none,

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ static void checkInheritanceClause(
249249
inheritedTy = layout.explicitSuperclass;
250250
}
251251

252+
if (inheritedTy->is<ParametrizedProtocolType>()) {
253+
if (!isa<ProtocolDecl>(decl)) {
254+
decl->diagnose(diag::inheritance_from_parametrized_protocol,
255+
inheritedTy);
256+
}
257+
continue;
258+
}
259+
252260
// If this is an enum inheritance clause, check for a raw type.
253261
if (isa<EnumDecl>(decl)) {
254262
// Check if we already had a raw type.

0 commit comments

Comments
 (0)