Skip to content

Commit c6a9226

Browse files
authored
Merge pull request #84665 from egorzhdan/egorzhdan/frt-objc-class
[cxx-interop] Avoid spurious references to `_OBJC_CLASS` symbols for C++ foreign reference types
2 parents 876fd51 + e0df8cd commit c6a9226

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/AST/Type.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4409,6 +4409,12 @@ bool Type::findIf(llvm::function_ref<bool(Type)> pred) const {
44094409
}
44104410

44114411
TypeTraitResult TypeBase::canBeClass() {
4412+
// Foreign reference types are represented as Swift classes in the AST,
4413+
// however, they use custom retain/release operations, and therefore aren't
4414+
// AnyObjects.
4415+
if (isForeignReferenceType())
4416+
return TypeTraitResult::IsNot;
4417+
44124418
// Any bridgeable object type can be a class.
44134419
if (isBridgeableObjectType())
44144420
return TypeTraitResult::Is;

test/Interop/Cxx/foreign-reference/array-of-classes.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ func go() {
5858
y.append(x)
5959
// CHECK: 1
6060
print(y.count)
61+
62+
var loopCount = 0
63+
for it in y {
64+
// CHECK: RefType()
65+
print(it)
66+
loopCount += 1
67+
}
68+
// CHECK: 1
69+
print(loopCount)
6170
}
6271

6372
go()

0 commit comments

Comments
 (0)