Skip to content

Commit 2133c94

Browse files
committed
[stdlib] Optional conforms to _BitwiseCopyable.
1 parent bac9e94 commit 2133c94

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

stdlib/public/core/Optional.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,7 @@ extension Optional: _ObjectiveCBridgeable {
782782
#endif
783783

784784
extension Optional: Sendable where Wrapped: Sendable { }
785+
786+
#if $BitwiseCopyable
787+
extension Optional: _BitwiseCopyable where Wrapped: _BitwiseCopyable { }
788+
#endif

test/Sema/bitwise_copyable.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,36 @@ func passAnyAny(_ a: any Any) { take3(a) } // expected-error {{type_does_not_con
154154
func passString(_ s: String) { take3(s) } // expected-error {{type_does_not_conform_decl_owner}}
155155
// expected-note@-17 {{where_requirement_failure_one_subst}}
156156

157+
extension Optional {
158+
struct Some : _BitwiseCopyable {
159+
var wrapped: Wrapped // expected-error {{non_bitwise_copyable_type_member}}
160+
}
161+
}
162+
163+
extension Optional where Wrapped : _BitwiseCopyable {
164+
struct Some2 : _BitwiseCopyable {
165+
var wrapped: Wrapped
166+
}
167+
}
168+
169+
struct S_Explicit_With_Generic_Optional<T> : _BitwiseCopyable {
170+
var o: Optional<T> // expected-error {{non_bitwise_copyable_type_member}}
171+
}
172+
173+
struct S_Explicit_With_2_Generic_Optionals<T> : _BitwiseCopyable {
174+
var o1: Optional<T> // expected-error {{non_bitwise_copyable_type_member}}
175+
var o2: T? // expected-error {{non_bitwise_copyable_type_member}}
176+
}
177+
178+
struct S_Explicit_With_BitwiseCopyable_Generic_Optional<T : _BitwiseCopyable> : _BitwiseCopyable {
179+
var o: Optional<T>
180+
}
181+
182+
struct S_Explicit_With_2_BitwiseCopyable_Generic_Optional<T : _BitwiseCopyable> : _BitwiseCopyable {
183+
var o: Optional<T>
184+
var o2: T?
185+
}
186+
157187
//==============================================================================
158188
//==========================STDLIB-DEPENDENCY TESTS=(BEGIN)==================={{
159189
//==============================================================================

0 commit comments

Comments
 (0)