Skip to content

Commit c38f53d

Browse files
committed
AST: Add ExistentialLayout::isErrorExistential()
1 parent cf45593 commit c38f53d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/swift/AST/ExistentialLayout.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ struct ExistentialLayout {
5858
return requiresClass && !containsNonObjCProtocol;
5959
}
6060

61+
// Does this existential contain the Error protocol?
6162
bool isExistentialWithError(ASTContext &ctx) const;
6263

64+
// Does this existential consist of an Error protocol only with no other
65+
// constraints?
66+
bool isErrorExistential() const;
67+
6368
ArrayRef<ProtocolType *> getProtocols() const {
6469
if (singleProtocol)
6570
return ArrayRef<ProtocolType *>{&singleProtocol, 1};

lib/AST/Type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,13 @@ bool TypeBase::isAnyObject() {
602602
return canTy.getExistentialLayout().isAnyObject();
603603
}
604604

605+
bool ExistentialLayout::isErrorExistential() const {
606+
auto protocols = getProtocols();
607+
return (!requiresClass &&
608+
protocols.size() == 1 &&
609+
protocols[0]->getDecl()->isSpecificProtocol(KnownProtocolKind::Error));
610+
}
611+
605612
bool ExistentialLayout::isExistentialWithError(ASTContext &ctx) const {
606613
auto errorProto = ctx.getProtocol(KnownProtocolKind::Error);
607614
if (!errorProto) return false;

0 commit comments

Comments
 (0)