Skip to content

[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
merged 6 commits into from
Nov 13, 2024

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Nov 12, 2024

  • Avoid calling performStmtDiagnostics in CSApply, instead leaving it up to the SyntacticDiagnosticWalker
  • Ensure we run performStmtDiagnostics for catch clauses, including allowing the ambiguous where clause diagnostic to be emitted for it
  • Cleanup diagnoseStmtAvailability + ExprAvailabilityWalker a bit
  • Make sure we visit MacroExpansionDecl args, I missed this in [Sema] Consistently run MiscDiagnostics on macro arguments #77534

Resolves #77453
Resolves #77553

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.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

Copy link
Contributor

@tshortli tshortli left a 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.

@hamishknight hamishknight merged commit 1965f96 into swiftlang:main Nov 13, 2024
7 checks passed
@hamishknight hamishknight deleted the statement-misc-diags branch November 13, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Existential spelling diagnostic missing for catch Duplicate statement diagnostics in result builder
3 participants