Skip to content

Commit cc1d258

Browse files
authored
Merge pull request #14387 from rudkx/CanType-getOptionalObjectType
Add CanType::getOptionalObjectType for staging a rename.
2 parents 3bdb92c + b253f94 commit cc1d258

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/swift/AST/Type.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ class CanType : public Type {
391391
static bool isObjCExistentialTypeImpl(CanType type);
392392
static CanType getAnyOptionalObjectTypeImpl(CanType type,
393393
OptionalTypeKind &kind);
394+
static CanType getOptionalObjectTypeImpl(CanType type);
394395
static CanType getReferenceStorageReferentImpl(CanType type);
395396
static CanType getWithoutSpecifierTypeImpl(CanType type);
396397

@@ -457,6 +458,10 @@ class CanType : public Type {
457458
NominalTypeDecl *getAnyNominal() const;
458459
GenericTypeDecl *getAnyGeneric() const;
459460

461+
CanType getOptionalObjectType() const {
462+
return getOptionalObjectTypeImpl(*this);
463+
}
464+
460465
CanType getAnyOptionalObjectType() const {
461466
OptionalTypeKind kind;
462467
return getAnyOptionalObjectTypeImpl(*this, kind);

lib/AST/Type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ CanType CanType::getAnyOptionalObjectTypeImpl(CanType type,
526526
return CanType();
527527
}
528528

529+
CanType CanType::getOptionalObjectTypeImpl(CanType type) {
530+
if (auto boundTy = dyn_cast<BoundGenericEnumType>(type))
531+
if (boundTy->getDecl()->classifyAsOptionalType() == OTK_Optional)
532+
return boundTy.getGenericArgs()[0];
533+
return CanType();
534+
}
535+
529536
Type TypeBase::getAnyPointerElementType(PointerTypeKind &PTK) {
530537
auto &C = getASTContext();
531538
if (auto nominalTy = getAs<NominalType>()) {

0 commit comments

Comments
 (0)