Skip to content

confirmation() does not work from @MainActor tests #622

Closed
@macguru

Description

@macguru

Description

The following test function will not compile in the Swift 6 language mode:

@MainActor @Test func example() async {
	await confirmation { _ in } // Error: Sending main actor-isolated value of type '(Confirmation) async -> ()' with later accesses to nonisolated context risks causing data races
}

Expected behavior

I think this should just work. confirmation() should take (and respect) an additional isolation argument isolation: isolated (any Actor)? = #isolation.

Proposed new signature (also discussed here):

func confirmation<R>(
    _ comment: Testing.Comment? = nil,
    expectedCount: Int = 1,
    isolation: isolated (any Actor)? = #isolation,
    sourceLocation: Testing.SourceLocation = #_sourceLocation,
    _ body: (Testing.Confirmation) async throws -> R
) async rethrows -> R

Actual behavior

No response

Steps to reproduce

No response

swift-testing version/commit hash

Xcode 16 beta 5

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1)
Target: arm64-apple-macosx15.0
Darwin Mac.localdomain 24.0.0 Darwin Kernel Version 24.0.0: Wed Aug 7 03:08:56 PDT 2024; root:xnu-11215.1.9~22/RELEASE_ARM64_T6020 arm64

Metadata

Metadata

Assignees

Labels

bug🪲 Something isn't workingconcurrency🔀 Swift concurrency/sendability issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions