Skip to content

Commit 3acae8f

Browse files
committed
Add a TypeBase::isAny helper.
1 parent 7483a6f commit 3acae8f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ class alignas(1 << TypeAlignInBits) TypeBase {
402402
/// hasReferenceSemantics() - Do objects of this type have reference
403403
/// semantics?
404404
bool hasReferenceSemantics();
405+
406+
/// Is this the 'Any' type?
407+
bool isAny();
405408

406409
/// Are values of this type essentially just class references,
407410
/// possibly with some sort of additional information?

lib/AST/Type.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ bool TypeBase::hasReferenceSemantics() {
8989
return getCanonicalType().hasReferenceSemantics();
9090
}
9191

92+
bool TypeBase::isAny() {
93+
if (auto comp = getAs<ProtocolCompositionType>())
94+
if (comp->getProtocols().empty())
95+
return true;
96+
97+
return false;
98+
}
99+
92100
bool TypeBase::isAnyClassReferenceType() {
93101
return getCanonicalType().isAnyClassReferenceType();
94102
}
@@ -1953,9 +1961,8 @@ getObjCObjectRepresentable(Type type, const DeclContext *dc) {
19531961

19541962
// Any can be bridged to id.
19551963
if (type->getASTContext().LangOpts.EnableIdAsAny) {
1956-
if (auto protoCompTy = type->getAs<ProtocolCompositionType>()) {
1957-
if (protoCompTy->getProtocols().empty())
1958-
return ForeignRepresentableKind::Bridged;
1964+
if (type->isAny()) {
1965+
return ForeignRepresentableKind::Bridged;
19591966
}
19601967
}
19611968

0 commit comments

Comments
 (0)