Skip to content
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

Do not perform full expansion of #expect() when try or await is present. #790

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

@@ -477,6 +466,22 @@ private func _parseCondition(negating expr: ExprSyntax, isParenthetical: Bool, f
///
/// - 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

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.
2 participants