Skip to content

Commit fc23339

Browse files
committed
[AST] Add isOptional method to TypeBase
In `main` this method was added by 9ed732f. Since that commit is rather large, only cherry-pick the `isOptional` method to 5.5.
1 parent 2878ab4 commit fc23339

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ class alignas(1 << TypeAlignInBits) TypeBase {
795795
/// Check if this type is equal to Swift.Bool.
796796
bool isBool();
797797

798+
/// Check if this type is equal to Swift.Optional.
799+
bool isOptional();
800+
798801
/// Check if this type is equal to Builtin.IntN.
799802
bool isBuiltinIntegerType(unsigned bitWidth);
800803

lib/AST/Type.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,16 @@ bool TypeBase::isBool() {
628628
return false;
629629
}
630630

631+
/// Check if this type is equal to Swift.Bool.
632+
bool TypeBase::isOptional() {
633+
if (auto generic = getAnyGeneric()) {
634+
if (isa<EnumDecl>(generic)) {
635+
return getASTContext().getOptionalDecl() == generic;
636+
}
637+
}
638+
return false;
639+
}
640+
631641
Type TypeBase::getRValueType() {
632642
// If the type is not an lvalue, this is a no-op.
633643
if (!hasLValueType())

0 commit comments

Comments
 (0)