swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.37k stars 10.34k forks source link

🍒[cxx-interop] C++ reference types are not `AnyObject`s #76720

Closed egorzhdan closed 2 days ago

egorzhdan commented 2 days ago

Explanation: C++ foreign reference types have custom reference counting mechanisms, so they cannot conform to AnyObject. Currently Swift's type system treats C++ FRTs as AnyObjects on non-Darwin platforms, which is incorrect. This change makes sure the behavior is consistent with Darwin platform, i.e. a cast of C++ FRT to AnyObject is rejected by the typechecker. Scope: Makes sure the special typechecker rule for FRTs is applied when Obj-C interop is disabled. Risk: Low, only takes effect when Obj-C interop is disabled, and FRTs are used. Testing: Enabled an existing compiler test on Linux and Windows. Issue: rdar://136664617 Reviewer: @Xazax-hun

Original PR: https://github.com/swiftlang/swift/pull/74185

egorzhdan commented 2 days ago

@swift-ci please test