Skip to content

await fulfillment(...) triggers a concurrency error in Swift 6 mode #507

Open
@cthielen

Description

@cthielen

The following code produces a concurrency error in Swift 6 mode:

@MainActor
func test_bla() async {
    let something = expectation(description: "bla")
    Task {
        try? await Task.sleep(for: .seconds(1.0))
        something.fulfill()
    }
    await fulfillment(of: [something])
}

(Credit Gero Herk for the sample, from https://forums.swift.org/t/swift-5-10-concurrency-and-xctest/69929/6)

The error is:

await fulfillment(of: [something], timeout: 5)
      `- warning: sending main actor-isolated value of type 'SomeXCTestCase' with later accesses to nonisolated context risks causing data races; this is an error in the Swift 6 language mode

This was temporarily fixed for the 5.10 branch using @_unsafeInheritExecutor: #479, but it is occurring now on Swift 6 OSS toolchains.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions