You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggest conditional conformance to Sendable derived from instance storage.
When proposing to annotate a public type as `Sendable` due to the
`-require-explicit-sendable` command-line parameter, suggest a
conditional conformance when it can be determined that a generic type
would be `Sendable` when certain type parameters are `Sendable`.
For example, given this type:
public struct DictionaryHolder<T: Hashable, U, V> {
var member: [T: (U, V?)]
}
We will now produce a Fix-It that suggests that one add:
extension DictionaryHolder: Sendable
where T: Sendable, U: Sendable, V: Sendable { }
Copy file name to clipboardExpand all lines: test/Concurrency/require-explicit-sendable.swift
+19-2Lines changed: 19 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -29,13 +29,13 @@ public class C2 { // expected-warning{{public class 'C2' does not specify whethe
29
29
}
30
30
31
31
publicstructS3<T>{ // expected-warning{{public generic struct 'S3' does not specify whether it is 'Sendable' or not}}
32
-
// expected-note@-1{{add '@unchecked Sendable' conformance to generic struct 'S3' if this type manually implements concurrency safety}}{{21-21=: @unchecked Sendable}}
32
+
// expected-note@-1{{consider making generic struct 'S3' conform to the 'Sendable' protocol}}{{2-2=\n\nextension S3: Sendable where T: Sendable { \}\n}}
33
33
// expected-note@-2{{make generic struct 'S3' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension S3: Sendable { \}\n}}
34
34
vart:T
35
35
}
36
36
37
37
publicstructS4<T>{ // expected-warning{{public generic struct 'S4' does not specify whether it is 'Sendable' or not}}
38
-
// expected-note@-1{{add '@unchecked Sendable' conformance to generic struct 'S4' if this type manually implements concurrency safety}}{{21-21=: @unchecked Sendable}}
38
+
// expected-note@-1{{add '@unchecked Sendable' conformance to generic struct 'S4' if this type manually implements concurrency safety}}{{2-2=\n\nextension S4: @unchecked Sendable where T: Sendable { \}\n}}
39
39
// expected-note@-2{{make generic struct 'S4' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension S4: Sendable { \}\n}}
40
40
vart:T
41
41
varc:C
@@ -70,3 +70,20 @@ func testMe(s5: S5, s7: S7) {
70
70
acceptSendable(s5) // expected-warning{{conformance of 'S5' to 'Sendable' is unavailable}}
71
71
acceptSendable(s7) // expected-warning{{conformance of 'S7' to 'Sendable' is unavailable}}
72
72
}
73
+
74
+
publicstructS8<T:Hashable, U, V>{ // expected-warning{{public generic struct 'S8' does not specify whether it is 'Sendable' or not}}
75
+
// expected-note@-1{{consider making generic struct 'S8' conform to the 'Sendable' protocol}}{{2-2=\n\nextension S8: Sendable where T: Sendable, U: Sendable, V: Sendable { \}\n}}
76
+
// expected-note@-2{{make generic struct 'S8' explicitly non-Sendable to suppress this warning}}
77
+
varmember:[T:(U,V?)]
78
+
}
79
+
80
+
publicprotocolP2{
81
+
associatedtypeA
82
+
}
83
+
84
+
publicstructS9<T:P2&Hashable>{
85
+
// expected-warning@-1{{public generic struct 'S9' does not specify whether it is 'Sendable' or not}}
86
+
// expected-note@-2{{consider making generic struct 'S9' conform to the 'Sendable' protocol}}{{2-2=\n\nextension S9: Sendable where T: Sendable, T.A: Sendable { \}\n}}
87
+
// expected-note@-3{{make generic struct 'S9' explicitly non-Sendable to suppress this warning}}
0 commit comments