Skip to content

Inherit isolation in #expect(exitsWith:). #736

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Sep 27, 2024

This PR ensures the body of the implementation of #expect(exitsWith:) inherits isolation from the caller. The actual body closure passed to the macro cannot inherit isolation as it runs in a separate process, but the glue code we emit needs to inherit so that if the caller is actor-isolated, the code compiles cleanly. Without this change, the following test fails to compile:

@MainActor @Test func f() async {
  await #expect(exitsWith: .failure) { /* ... */ }
  // 🛑 ^ ^ ^ sending main actor-isolated value of type '() -> [Comment]' with later accesses to nonisolated context risks causing data races
}

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR ensures the body of _the implementation of_ `#expect(exitsWith:)` inherits isolation from the caller. The actual body closure passed to the macro cannot inherit isolation as it runs in a separate process, but the glue code we emit needs to inherit so that if the caller is actor-isolated, the code compiles cleanly. Without this change, the following test fails to compile:

```swift
@mainactor @test func f() async {
  await #expect(exitsWith: .failure) { /* ... */ }
  // 🛑 ^ ^ ^ sending main actor-isolated value of type '() -> [Comment]' with later accesses to nonisolated context risks causing data races
}
```
@grynspan grynspan added bug 🪲 Something isn't working concurrency Swift concurrency/sendability issues exit-tests ☠️ Work related to exit tests labels Sep 27, 2024
@grynspan grynspan self-assigned this Sep 27, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit 1b04184 into main Sep 30, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/exit-test-isolation branch September 30, 2024 22:41
@grynspan grynspan added this to the Swift 6.1 milestone Oct 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug 🪲 Something isn't working concurrency Swift concurrency/sendability issues exit-tests ☠️ Work related to exit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants