Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift-Testing Swift 6 Strict Concurrency Legit Build Failure? #74882

Open
vanvoorden opened this issue Jul 2, 2024 · 9 comments
Open

Swift-Testing Swift 6 Strict Concurrency Legit Build Failure? #74882

vanvoorden opened this issue Jul 2, 2024 · 9 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features

Comments

@vanvoorden
Copy link
Contributor

vanvoorden commented Jul 2, 2024

Description

https://forums.swift.org/t/swift-testing-swift-6-strict-concurrency-legit-build-failure/72824/1

Hi! I'm experimenting with swift-testing and Swift 6 strict concurrency checking. I'm seeing some not-super-clear build failure. Maybe this is something that should work and might be fixed later this year… or maybe it's a legit failure and I should rethink how this test is built.

Here is a test that builds (and passes) from Swift 6 strict concurrency:

func doSomething(_: Int) async throws {
  
}

@Suite actor Tests {
  let count = 0
}

extension Tests {
  @Test func exampleBuilds() async throws {
    let count = 0
    try await doSomething(count)
    await #expect(throws: Never.self) {
      try await doSomething(count)
    }
    try await doSomething(self.count)
  }
}

Here is a test that fails to build from Swift 6 strict concurrency:

extension Tests {
  @Test func exampleFails() async throws {
    await #expect(throws: Never.self) {
      try await doSomething(self.count)
    }
  }
}

Here is the failure:

24 |     await #expect(throws: Never.self) {
25 |       try await doSomething(self.count)
26 |     }
   +--- macro expansion #expect ----------------------------------------
   |1 | Testing.__checkClosureCall(throws: Never.self, performing: {
   |  | `- error: sending 'self'-isolated value of type '() async throws -> ()' with later accesses to nonisolated context risks causing data races
   |2 |       try await doSomething(self.count)
   |3 |     }, expression: .__fromSyntaxNode("try await doSomething(self.count)"), comments: [], isRequired: false, sourceLocation: Testing.SourceLocation()).__expected()
   +--------------------------------------------------------------------
27 |   }
28 | }

Any ideas about what else I can do about that? I don't see this error when building from Swift 5 mode. Is this error legit? Should I rethink how I'm building this test? Any ideas about that would be great. Thanks!

Environment

swift-driver version: 1.110 Apple Swift version 6.0 (swiftlang-6.0.0.4.52 clang-1600.0.21.1.3)
Target: arm64-apple-macosx14.0

@vanvoorden vanvoorden added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jul 2, 2024
@vanvoorden
Copy link
Contributor Author

cc @grynspan

@hborla hborla added concurrency Feature: umbrella label for concurrency language features and removed triage needed This issue needs more specific labels labels Jul 14, 2024
@vanvoorden
Copy link
Contributor Author

extension Tests {
  @Test func exampleWorkaround() async throws {
    do {
      try await doSomething(self.count)
    } catch {
      #expect(false)
    }
  }
}

I'm unblocked with this workaround.

@gottesmm
Copy link
Contributor

gottesmm commented Aug 5, 2024

@vanvoorden I believe this is already fixed... can you try this with the latest snapshot or baring that, provide a full swift package that I can build that reproduces this?

@vanvoorden
Copy link
Contributor Author

@gottesmm This looks fixed in Xcode_16_beta_4. Thanks!

@grynspan
Copy link
Contributor

grynspan commented Aug 5, 2024

Thanks for confirming!

@grynspan grynspan closed this as completed Aug 5, 2024
@vanvoorden
Copy link
Contributor Author

@grynspan Ahh… actually the original test case was fixed… but this version still looks broken in Xcode_16_beta_4.

func doSomething(_: Int) async throws {
  
}

@Suite actor Tests {
  let count = 0
}

extension Tests {
  @Test func exampleFails() async throws {
    await #expect {
      try await doSomething(self.count)
    } throws: { _ in
      return true
    }
  }
}

With a similar error:

   +--- macro expansion #expect ----------------------------------------
   |1 | Testing.__checkClosureCall(performing: {
   |  | `- error: sending 'self'-isolated value of type '() async throws -> ()' with later accesses to nonisolated context risks causing data races
   |2 |       try await doSomething(self.count)
   |3 |     }, throws: { _ in
   +--------------------------------------------------------------------

@grynspan
Copy link
Contributor

grynspan commented Aug 5, 2024

D'oh!

@grynspan grynspan reopened this Aug 5, 2024
@vanvoorden
Copy link
Contributor Author

@grynspan FWIW I am still unblocked on this new test case with a similar workaround from before.

@vanvoorden
Copy link
Contributor Author

provide a full swift package that I can build that reproduces this

https://github.com/vanvoorden/2024-08-05/

@gottesmm Here is the new repro. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

No branches or pull requests

4 participants