Fix SubMatch wrapped in Typed node by ensureNoLocalRefs#25778
Open
zielinsky wants to merge 3 commits intoscala:mainfrom
Open
Fix SubMatch wrapped in Typed node by ensureNoLocalRefs#25778zielinsky wants to merge 3 commits intoscala:mainfrom
SubMatch wrapped in Typed node by ensureNoLocalRefs#25778zielinsky wants to merge 3 commits intoscala:mainfrom
Conversation
SubMatch wrapped in Typed node by ensureNoLocalRefs
SubMatch wrapped in Typed node by ensureNoLocalRefsSubMatch wrapped in Typed node by ensureNoLocalRefs
Member
|
@EugeneFlesselle Can you take a look of this PR? thanks! |
noti0na1
reviewed
Apr 22, 2026
| case block @ Block(stats, expr) if !expr.isInstanceOf[Closure] => | ||
| val expr1 = ascribeType(expr, pt) | ||
| cpy.Block(block)(stats, expr1).withType(expr1.tpe) // no assignType here because avoid is redundant | ||
| case m @ Match(selector, cases) if m.isSubMatch => |
Member
There was a problem hiding this comment.
I'm not sure why we only need to handle SubMatch here?
Member
Author
There was a problem hiding this comment.
It's because of how transformMatch handles a simple Match vs SubMatch. For the first one, wrapping it in Typed is not a problem
Contributor
EugeneFlesselle
left a comment
There was a problem hiding this comment.
This caused PatternMatcher to miss the SubMatch and emit it as a raw ResultPlan, which after a few steps crashed BCodeBodyBuilder.
In that case it might be best to have the fix be in the PattenMatcher for SubCases specifically, rather than in the avoidance logic
| case block @ Block(stats, expr) if !expr.isInstanceOf[Closure] => | ||
| val expr1 = ascribeType(expr, pt) | ||
| cpy.Block(block)(stats, expr1).withType(expr1.tpe) // no assignType here because avoid is redundant | ||
| case m @ Match(selector, cases) if m.isSubMatch => |
Contributor
There was a problem hiding this comment.
IIUC this case is added to avoid the Typed wrapper?
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
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.
Fixes #25746
ensureNoLocalRefsin the typer wrappedSubMatchnode inTyped(SubMatch, String). This causedPatternMatcherto miss theSubMatchand emit it as a rawResultPlan, which after a few steps crashedBCodeBodyBuilder.How much have you relied on LLM-based tools in this contribution?
To help me identify the error.
How was the solution tested?
Tests are included.
Additional notes
My first attempt was to handle
Typed(t: SubMatch, _)incaseDefPlaninPatternMatcher, but I was afraid of silent errors by just strippingTyped.