-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Concurrency] Allow conditionally conforming to Sendable when confo…
#85605
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,42 @@ do { | |
| check(NonSendable()) // expected-warning {{type 'NonSendable' does not conform to the 'Sendable' protocol}} | ||
| check(NoInference()) // Ok | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a test for how this conditional conformance behavior works with classes and inheritance? and perhaps for completion, some also, when messing with whatever version is on the nightly godbolt, it also seems like this is accepted on the current snapshot (57cf4ce), which seems wrong, or at least confusing: actor A: ~Sendable {}presumably that is due to its being a edit: oh, and another case occurs to me – should we have a case to test a conditional Sendable conformance to another protocol that refines Sendable? |
||
| func takesSendable<T: Sendable>(_: T) {} | ||
|
|
||
| class MyValue {} // expected-note 2 {{class 'MyValue' does not conform to the 'Sendable' protocol}} | ||
|
|
||
| public struct D: ~Sendable { | ||
| } | ||
|
|
||
| extension D: Sendable {} // expected-error {{cannot both conform to and suppress conformance to 'Sendable'}} | ||
|
|
||
| takesSendable(D()) | ||
|
|
||
| public struct F<T>: ~Sendable { | ||
| let x: T | ||
| } | ||
|
|
||
| extension F: Sendable where T: Sendable { } | ||
|
|
||
| takesSendable(F(x: 42)) | ||
|
|
||
| public struct G<T, U>: ~Sendable { // expected-note {{making generic parameter 'U' conform to the 'Sendable' protocol}} | ||
| let t: T | ||
| let u: U // expected-warning {{stored property 'u' of 'Sendable'-conforming generic struct 'G' has non-Sendable type 'U'}} | ||
| } | ||
|
|
||
| extension G: Sendable where T: Sendable { } | ||
|
|
||
| takesSendable(G(t: "", u: 42)) | ||
| takesSendable(G(t: MyValue(), u: 0)) // expected-warning {{type 'MyValue' does not conform to the 'Sendable' protocol}} | ||
|
|
||
| public struct H<T, U>: ~Sendable { | ||
| let t: T | ||
| let u: U | ||
| } | ||
|
|
||
| extension H: Sendable where T: Sendable, U: Sendable { } | ||
|
|
||
| takesSendable(H(t: "", u: 42)) | ||
| takesSendable(H(t: "", u: MyValue())) // expected-warning {{type 'MyValue' does not conform to the 'Sendable' protocol}} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity – is this meant to be a check for 5.3 or 6.3? if it is 5.3, why is that version relevant?