Skip to content

Add CanType::getOptionalObjectType for staging a rename. #14387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ class CanType : public Type {
static bool isObjCExistentialTypeImpl(CanType type);
static CanType getAnyOptionalObjectTypeImpl(CanType type,
OptionalTypeKind &kind);
static CanType getOptionalObjectTypeImpl(CanType type);
static CanType getReferenceStorageReferentImpl(CanType type);
static CanType getWithoutSpecifierTypeImpl(CanType type);

Expand Down Expand Up @@ -457,6 +458,10 @@ class CanType : public Type {
NominalTypeDecl *getAnyNominal() const;
GenericTypeDecl *getAnyGeneric() const;

CanType getOptionalObjectType() const {
return getOptionalObjectTypeImpl(*this);
}

CanType getAnyOptionalObjectType() const {
OptionalTypeKind kind;
return getAnyOptionalObjectTypeImpl(*this, kind);
Expand Down
7 changes: 7 additions & 0 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ CanType CanType::getAnyOptionalObjectTypeImpl(CanType type,
return CanType();
}

CanType CanType::getOptionalObjectTypeImpl(CanType type) {
if (auto boundTy = dyn_cast<BoundGenericEnumType>(type))
if (boundTy->getDecl()->classifyAsOptionalType() == OTK_Optional)
return boundTy.getGenericArgs()[0];
return CanType();
}

Type TypeBase::getAnyPointerElementType(PointerTypeKind &PTK) {
auto &C = getASTContext();
if (auto nominalTy = getAs<NominalType>()) {
Expand Down