Skip to content

[cxx-interop] Foreign reference types should not satisfy : AnyObject constraint#90015

Open
egorzhdan wants to merge 1 commit into
swiftlang:mainfrom
egorzhdan:egorzhdan/frt-not-anyobject
Open

[cxx-interop] Foreign reference types should not satisfy : AnyObject constraint#90015
egorzhdan wants to merge 1 commit into
swiftlang:mainfrom
egorzhdan:egorzhdan/frt-not-anyobject

Conversation

@egorzhdan

Copy link
Copy Markdown
Contributor
protocol RequiresAnyObject : AnyObject {}

extension MyFRT : RequiresAnyObject {}

This should trigger a compiler error, since foreign reference types do not conform to AnyObject – they use custom reference counting mechanism.

As a side effect of this change, Unmanaged<MyFRT> now also triggers a compiler error. Unmanaged requires its wrapped type to be AnyObject. Swift allowed its usage with foreign reference types, however, that was an oversight.

rdar://179825120

…` constraint

```
protocol RequiresAnyObject : AnyObject {}

extension MyFRT : RequiresAnyObject {}
```
This should trigger a compiler error, since foreign reference types do not conform to `AnyObject` – they use custom reference counting mechanism.

As a side effect of this change, `Unmanaged<MyFRT>` now also triggers a compiler error. `Unmanaged` requires its wrapped type to be `AnyObject`. Swift allowed its usage with foreign reference types, however, that was an oversight.

rdar://179825120
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jun 17, 2026
@egorzhdan

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@egorzhdan

Copy link
Copy Markdown
Contributor Author

@swift-ci please test macOS

@egorzhdan

Copy link
Copy Markdown
Contributor Author

@swift-ci please test macOS

@egorzhdan

Copy link
Copy Markdown
Contributor Author

@swift-ci please test Linux

@egorzhdan

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

1 similar comment
@egorzhdan

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

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