Skip to content

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Apr 1, 2025

This PR adds a custom diagnostic for #expect(exitsWith:) if the passed closure visibly closes over any state (via a capture list). For example:

await #expect(exitsWith: .failure) { [x] in
  // ...
}

Produces:

🛑 Cannot specify a capture clause in closure passed to '#expect(exitsWith:_:)'

With a fix-it to remove the capture list.

Checklist:

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

…ist.

This PR adds a custom diagnostic for `#expect(exitsWith:)` if the passed closure
visibly closes over any state (via a capture list). For example:

```swift
await #expect(exitsWith: .failure) { [x] in
  // ...
}
```

Produces:

>  🛑 Cannot specify a capture clause in closure passed to '#expect(exitsWith:_:)'

With a fix-it to remove the capture list.
@grynspan grynspan added enhancement New feature or request exit-tests ☠️ Work related to exit tests macros 🔭 Related to Swift macros such as @Test or #expect labels Apr 1, 2025
@grynspan grynspan added this to the Swift 6.2 milestone Apr 1, 2025
@grynspan grynspan self-assigned this Apr 1, 2025
@grynspan
Copy link
Contributor Author

grynspan commented Apr 1, 2025

@swift-ci test

@grynspan grynspan merged commit 0e3bdfd into main Apr 1, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/capture-list-diagnostic branch April 1, 2025 18:05
@grynspan grynspan added the exit-test-capture-lists 🥍 Work related to exit test capture lists label Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request exit-test-capture-lists 🥍 Work related to exit test capture lists exit-tests ☠️ Work related to exit tests macros 🔭 Related to Swift macros such as @Test or #expect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants