Skip to content

Commit 0b92f0e

Browse files
committed
Make XCTestExpectation Sendable
This makes the `XCTestExpectation` class hierarchy conform to `Sendable`. This class and its descendants are designed to be used concurrently and are already internally concurrency-safe, so this conformance formally permits them to be used in Swift Concurrency APIs which enforce sendability. Includes a build-only test which has concurrency warnings enabled to validate the fix. rdar://95746454
1 parent 36d50c0 commit 0b92f0e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/XCTest/Public/Asynchronous/XCTestExpectation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212

1313
/// Expectations represent specific conditions in asynchronous testing.
14-
open class XCTestExpectation {
14+
open class XCTestExpectation: @unchecked Sendable {
1515

1616
private static var currentMonotonicallyIncreasingToken: UInt64 = 0
1717
private static func queue_nextMonotonicallyIncreasingToken() -> UInt64 {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %{swiftc} %s -typecheck -warn-concurrency -warnings-as-errors
2+
3+
#if os(macOS)
4+
import SwiftXCTest
5+
#else
6+
import XCTest
7+
#endif
8+
9+
let expectation = XCTestExpectation()
10+
Task.detached {
11+
expectation.fulfill()
12+
}

0 commit comments

Comments
 (0)