-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] A couple more MiscDiagnostics cleanups/fixes #77554
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
Merged
hamishknight
merged 6 commits into
swiftlang:main
from
hamishknight:statement-misc-diags
Nov 13, 2024
Merged
[Sema] A couple more MiscDiagnostics cleanups/fixes #77554
hamishknight
merged 6 commits into
swiftlang:main
from
hamishknight:statement-misc-diags
Nov 13, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I missed this in my previous PR, but this is needed to ensure we visit macro arguments for macro expansion exprs that have substitute MacroExpansionDecls since we prefer to visit the arguments on the decl once the expression has been expanded.
Instead, ensure we walk into expressions in SyntacticDiagnosticWalker, allowing `performStmtDiagnostics` to be called there for all statements present in the target. This avoids a case where we'd double diagnose. While here, inherit the walker from BaseDiagnosticWalker.
The walker here is really doing 2 completely separate things, split it into 2 walkers. For ExprAvailabilityWalker, we just want to recursively continue walking looking for any sub-expressions to diagnose. For StmtAvailabilityWalker we only want to walk the top-level statement, and are only interested in any TypeReprs it has. This lets us get rid of the special handling for BraceStmt.
This used to have some logic when multi-statement closures were type-checked differently, it's always true now.
Simplifies things a tiny amount, and ensures we don't attempt to walk into non-PatternBindingDecls, same as other MiscDiagnostic passes. I don't think this currently makes a difference since I don't believe we have any interesting cases where a Decl is nested in an Expr without an intermediate Stmt, but it's the right thing to do regardless.
Previously we would check if we have a SwitchStmt, and apply diagnostics such as `checkExistentialTypes` to the CaseStmts individually. This however would have been missed for `catch` statements. The change to consistently call `performStmtDiagnostics` in closures fixed this for `do-catch`'s in closures, this commit fixes it for those outside of closures. Because this is source breaking, the existential diagnostic is downgraded to a warning until Swift 7 for catch statements specifically. While here, also apply the ambiguous where clause diagnostic to `catch` statements.
b9d09b6
to
b644cd8
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
tshortli
approved these changes
Nov 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Availability changes look good.
xedin
approved these changes
Nov 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
performStmtDiagnostics
in CSApply, instead leaving it up to the SyntacticDiagnosticWalkerperformStmtDiagnostics
forcatch
clauses, including allowing the ambiguous where clause diagnostic to be emitted for itdiagnoseStmtAvailability
+ExprAvailabilityWalker
a bitResolves #77453
Resolves #77553