-
Notifications
You must be signed in to change notification settings - Fork 10.6k
A few pattern cleanups + fixes #84149
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
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
1f857a4
to
c8d7d47
Compare
Avoid walking TapExprs, SingleValueStmtExprs, and key paths. The latter is important since they can contain invalid VarDecls that will no longer be visited by the ASTWalker after key path resolution, so we don't want to create case body vars for them.
We don't wire up the parent variables until after type-checking, and `recordInferredSwitchCasePatternVars` already handles joining the pattern types, so we can remove this.
We want to call the `bodyEmitter`, since that has the extra logic necessary to handle `do-catch` statements. Previously this didn't cause any issues since `hasCaseBodyVariables` would have always been true for parsed `do-catch`s, but I'm planning on changing that.
We don't need to store a `MutableArrayRef`.
We don't really care about the distinction between empty and nil here.
Rather than waiting until type-checking, we can set the parents immediately when we create the CaseStmt. This requires fixing up NamingPatternRequest to look at the recursive parent statement as now the VarDecl may have a variable parent.
This allows us to re-use the same logic to create the case body variables.
…tyMismatch` Now that we wire up the parents up-front, this no longer needs to set the parents. As such, remove the logic and rename to reflect the fact that it now just diagnoses mutability mismatches.
`findParentPatternCaseStmtAndPattern` does more work than is necessary for this, we just want the parent of the canonical var.
Add the extra logic to `VarDecl::getParentPattern` necessary to handle fallthrough and case body variables instead. This also changes the behavior for case body vars - previously we would return the first pattern in the CaseStmt, but that's not necessarily correct. Instead, return the first pattern that actually binds the variable.
We don't want to just check the first pattern, we're interested in the first pattern that binds the given variable. That can be determined by checking if it's canonical or not.
This normally gets populated by successful type-checking, we still want to populate it if we fail though to avoid attempting to type-check the parent statement again.
c8d7d47
to
10ed175
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
@swift-ci please SourceKit stress test |
xedin
approved these changes
Sep 9, 2025
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.
CaseStmt::createImplicit
and re-use the existing implementation for creating the case body variablesVarDecl::getParentPattern
andVarDecl::getRecursiveParentPatternStmt
and removefindParentPatternCaseStmtAndPattern
markInvalid
to avoid double-type-checking