Skip to content

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Oct 30, 2024

For reasons that have been documented at length (see #162), we aren't able to correctly expand conditions on #expect() or #require() that have effects (try or await.) We aren't currently detecting all possible patterns that expand incorrectly. This PR causes us to back out of the full expansion if the try or await keyword is present anywhere inside an expectation condition expression.

Resolves #783.

Checklist:

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

… present.

For reasons that have been documented at length (see #162), we aren't able to
correctly expand conditions on `#expect()` or `#require()` that have effects
(`try` or `await`.) We aren't currently detecting all possible patterns that
expand incorrectly. This PR causes us to back out of the full expansion if the
`try` or `await` keyword is present _anywhere_ inside an expectation condition
expression.

Resolves #783.
@grynspan grynspan added the bug 🪲 Something isn't working label Oct 30, 2024
@grynspan grynspan added this to the Swift 6.1 milestone Oct 30, 2024
@grynspan grynspan self-assigned this Oct 30, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

///
/// - Returns: An instance of ``Condition`` describing `expr`.
private func _parseCondition(from expr: ExprSyntax, for macro: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) -> Condition {
// Handle closures with a single expression in them (e.g. { $0.foo() })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this up so that closure "expansion" (not really but sure why not) still happens. If we ever actually start doing fun things with closures, we'll probably need to move this back down?

@grynspan
Copy link
Contributor Author

grynspan commented Nov 2, 2024

@swift-ci test

@grynspan
Copy link
Contributor Author

grynspan commented Nov 3, 2024

@swift-ci test Windows

@grynspan grynspan merged commit 6a2b04c into main Nov 5, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/783-try-await-keywords branch November 5, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#expect doesn't expect that there may be a sub-expression that has try on the right side of binary operator.

3 participants