Skip to content

🍒[cxx-interop] C++ reference types are not AnyObjects #76720

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
Sep 26, 2024

Conversation

egorzhdan
Copy link
Contributor

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: #74185

C++ foreign reference types have custom reference counting mechanisms, so they cannot conform to `AnyObject`.

Currently Swift's type system treats C++ FRTs as `AnyObject`s 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.

rdar://136664617
(cherry picked from commit 82c076c)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Sep 26, 2024
@egorzhdan egorzhdan requested a review from a team as a code owner September 26, 2024 16:55
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan enabled auto-merge September 26, 2024 17:36
@egorzhdan egorzhdan merged commit 0ba79e4 into release/6.0.2 Sep 26, 2024
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/6.0.2-frt-test-nonobjc branch September 26, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants