Skip to content

Suppress the complex expansion of expectations when we see effects in the lexical context. #1161

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

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Jun 17, 2025

This PR changes the behaviour of the testing library for expressions such as:

try #expect(a == b)

Currently, we don't expand that expression correctly because we can't tell where the try keyword should be applied. It sometimes expands and sometimes doesn't. This PR detects the presence of those keywords (with a recent-enough toolchain) and, if found, disables the fancy expansion in favour of a simpler one that is less likely to fail to compile.

More thorough support for effectful expressions in expectations is tracked by #840 which involves fully refactoring the implementation of the #expect() macro. See also #162 for some more context.

Checklist:

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

… the lexical context.

This PR changes the behaviour of the testing library for expressions such as:

```swift
try #expect(a == b)
```

Currently, we don't expand that expression correctly because we can't tell where
the `try` keyword should be applied. It sometimes expands and sometimes doesn't.
This PR detects the presence of those keywords (with a recent-enough toolchain)
and, if found, disables the fancy expansion in favour of a simpler one that is
less likely to fail to compile.

More thorough support for effectful expressions in expectations is tracked by #840
which involves fully refactoring the implementation of the `#expect()` macro.
@grynspan grynspan added this to the Swift 6.x milestone Jun 17, 2025
@grynspan grynspan self-assigned this Jun 17, 2025
@grynspan grynspan added bug 🪲 Something isn't working public-api Affects public API macros 🔭 Related to Swift macros such as @Test or #expect labels Jun 17, 2025
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit eeeffd4 into main Jun 18, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/suppress-expectation-expansion-when-effects-in-lexical-context branch June 18, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working macros 🔭 Related to Swift macros such as @Test or #expect public-api Affects public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants