pointfreeco / swift-concurrency-extras

Useful, testable Swift concurrency.
MIT License
343 stars 23 forks source link

Xcode 16 Beta + Swift-Testing challenges #27

Closed Tyler-Keith-Thompson closed 4 months ago

Tyler-Keith-Thompson commented 4 months ago

Description

When using Swift-Testing 0.10.0 and the Xcode 16 beta I'm running into some unexpected behavior. If you use the Swift-Testing try await confirmation { inside a try await withMainSerialExecutor { closure, you get the following error:

Error: Sending main actor-isolated value of type '(Confirmation) async throws -> ()' with later accesses to nonisolated context risks causing data races

There's a temporary workaround where you can simply reverse the order, have try await confirmation outside and try await withMainSerialExecutor inside that closure, but this isn't practical for all use cases.

I also realize this is a beta and subject to change, but I thought I'd report this anyways.

Checklist

Expected behavior

I guess I'm not sure? If there really is a data race risk then it seems like that risk should exist in either case, but it seems like a false positive.

Actual behavior

Error: Sending main actor-isolated value of type '(Confirmation) async throws -> ()' with later accesses to nonisolated context risks causing data races

Steps to reproduce

  1. Create a local SPM package, enable strict concurrency checking and swiftLanguageVersions: [.version("6")]
  2. Pull in .package(url: "https://github.com/apple/swift-testing.git", from: "0.10.0")
  3. Write a test like:
    try await withMainSerialExecutor {
    try await confirmation { exp in
        exp()
    }
    }

swift-concurrency-extras version information

1.1.0

Destination operating system

macOS 14.5

Xcode version information

16 Beta (16A5171c)

Swift Compiler version information

Swift 6
stephencelis commented 4 months ago

@Tyler-Keith-Thompson Can you attach a full project that can be opened in Xcode 16 to demonstrate the problem? Also, I'm inclined to convert this to a discussion for the moment, since we're talking Apple beta, but if you can share an easy repro we'll find the time to check it out soon.

Tyler-Keith-Thompson commented 4 months ago

This sample project reproduces the problem, simply open the Package with Xcode 16 and Command + U.

I'm all good for converting to a discussion, I've certainly brought this up very early.