diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 6f5ba55d4637a..4c709ccfede2b 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -4413,6 +4413,12 @@ bool Type::findIf(llvm::function_ref pred) const { } TypeTraitResult TypeBase::canBeClass() { + // Foreign reference types are represented as Swift classes in the AST, + // however, they use custom retain/release operations, and therefore aren't + // AnyObjects. + if (isForeignReferenceType()) + return TypeTraitResult::IsNot; + // Any bridgeable object type can be a class. if (isBridgeableObjectType()) return TypeTraitResult::Is; diff --git a/test/Interop/Cxx/foreign-reference/array-of-classes.swift b/test/Interop/Cxx/foreign-reference/array-of-classes.swift index e9db746d53c63..17f135971f49c 100644 --- a/test/Interop/Cxx/foreign-reference/array-of-classes.swift +++ b/test/Interop/Cxx/foreign-reference/array-of-classes.swift @@ -58,6 +58,15 @@ func go() { y.append(x) // CHECK: 1 print(y.count) + + var loopCount = 0 + for it in y { +// CHECK: RefType() + print(it) + loopCount += 1 + } +// CHECK: 1 + print(loopCount) } go()