Skip to content

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Jan 15, 2025

Other than the body closure, the arguments to #expect(exitsWith:) are not guaranteed to be literals or otherwise context-free, but we capture them during macro expansion. This can result in obscure errors if the developer writes an exit test with an argument that is computed:

let foo = ... await #expect(exitsWith: self.exitCondition(for: foo)) { // 🛑 error: closure captures 'foo' before it is declared // 🛑 error: enum declaration cannot close over value 'self' defined in outer scope // (and other possible errors) ... }

This PR removes the macro's compile-time dependency on its exitCondition and sourceLocation arguments and introduces an ID type to identify exit tests (instead of using their source locations as unique IDs.) The ID type is meant to be a UUID, but for the moment I've just strung together two 64-bit integers instead to avoid a dependency on Foundation or platform API.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.
Other than the body closure, the arguments to `#expect(exitsWith:)` are not guaranteed to be literals or otherwise context-free, but we capture them during macro expansion. This can result in obscure errors if the developer writes an exit test with an argument that is computed: ```swift let foo = ... await #expect(exitsWith: self.exitCondition(for: foo)) { // 🛑 error: closure captures 'foo' before it is declared // 🛑 error: enum declaration cannot close over value 'self' defined in outer scope // (and other possible errors) ... } ``` This PR removes the macro's compile-time dependency on its `exitCondition` and `sourceLocation` arguments and introduces an `ID` type to identify exit tests (instead of using their source locations as unique IDs.) The `ID` type is meant to be a UUID, but for the moment I've just strung together two 64-bit integers instead to avoid a dependency on Foundation or platform API.
@grynspan grynspan added bug 🪲 Something isn't working exit-tests ☠️ Work related to exit tests labels Jan 15, 2025
@grynspan grynspan added this to the Swift 6.x milestone Jan 15, 2025
@grynspan grynspan self-assigned this Jan 15, 2025
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit 46afc15 into main Jan 15, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/exit-test-arguments-are-captured branch January 15, 2025 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working exit-tests ☠️ Work related to exit tests

2 participants