Skip to content

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
@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.

3 participants