Skip to content

Commit 879fc76

Browse files
author
Harlan Haskins
committed
[TBDGen] Allow #warning/#error in protocols
Resolves [SR-9519](https://bugs.swift.org/browse/SR-9519)
1 parent 311a78d commit 879fc76

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,43 @@ static bool protocolDescriptorHasRequirements(ProtocolDecl *proto) {
426426
return false;
427427
}
428428

429+
#ifndef NDEBUG
430+
static bool isValidProtocolMemberForTBDGen(const Decl *D) {
431+
switch (D->getKind()) {
432+
case DeclKind::TypeAlias:
433+
case DeclKind::AssociatedType:
434+
case DeclKind::Var:
435+
case DeclKind::Subscript:
436+
case DeclKind::PatternBinding:
437+
case DeclKind::Func:
438+
case DeclKind::Accessor:
439+
case DeclKind::Constructor:
440+
case DeclKind::Destructor:
441+
case DeclKind::IfConfig:
442+
case DeclKind::PoundDiagnostic:
443+
return true;
444+
case DeclKind::Enum:
445+
case DeclKind::Struct:
446+
case DeclKind::Class:
447+
case DeclKind::Protocol:
448+
case DeclKind::GenericTypeParam:
449+
case DeclKind::Module:
450+
case DeclKind::Param:
451+
case DeclKind::EnumElement:
452+
case DeclKind::Extension:
453+
case DeclKind::TopLevelCode:
454+
case DeclKind::Import:
455+
case DeclKind::PrecedenceGroup:
456+
case DeclKind::MissingMember:
457+
case DeclKind::EnumCase:
458+
case DeclKind::InfixOperator:
459+
case DeclKind::PrefixOperator:
460+
case DeclKind::PostfixOperator:
461+
return false;
462+
}
463+
}
464+
#endif
465+
429466
void TBDGenVisitor::visitProtocolDecl(ProtocolDecl *PD) {
430467
if (!PD->isObjC()) {
431468
addSymbol(LinkEntity::forProtocolDescriptor(PD));
@@ -480,11 +517,7 @@ void TBDGenVisitor::visitProtocolDecl(ProtocolDecl *PD) {
480517
// (NB. anything within an active IfConfigDecls also appears outside). Let's
481518
// assert this fact:
482519
for (auto *member : PD->getMembers()) {
483-
auto isExpectedKind =
484-
isa<TypeAliasDecl>(member) || isa<AssociatedTypeDecl>(member) ||
485-
isa<AbstractStorageDecl>(member) || isa<PatternBindingDecl>(member) ||
486-
isa<AbstractFunctionDecl>(member) || isa<IfConfigDecl>(member);
487-
assert(isExpectedKind &&
520+
assert(isValidProtocolMemberForTBDGen(member) &&
488521
"unexpected member of protocol during TBD generation");
489522
}
490523
#endif

test/Sema/pound_diagnostics.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ class C { // expected-note {{in declaration of 'C'}}
7272
#error("private error") // expected-error {{private error}}
7373
func bar() {}
7474
}
75+
76+
protocol MyProtocol {
77+
#warning("warnings can show up in protocols too!") // expected-warning {{warnings can show up in protocols too!}}
78+
}
79+

0 commit comments

Comments
 (0)