Skip to content

Commit bf0bb31

Browse files
author
Harlan Haskins
authored
Merge pull request #21393 from harlanhaskins/oops-indeed
[TBDGen] Allow #warning/#error in protocols
2 parents c17423d + c9980f1 commit bf0bb31

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

lib/TBDGen/TBDGen.cpp

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

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

test/Sema/pound_diagnostics.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ 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+
80+
#warning("""
81+
warnings support multi-line string literals
82+
""") // expected-warning @-2 {{warnings support multi-line string literals}}
83+
84+
#warning(#"warnings support \(custom string delimiters)"#) // expected-warning {{warnings support \\(custom string delimiters)}}

0 commit comments

Comments
 (0)