Fix match-pattern miscompile from stale unboxable marks#525
Open
nbeerbower wants to merge 2 commits into
Open
Conversation
Same bug pattern as PRs #519 and #522: a prior same-named binding (e.g. `for (let i = 0; ...)` counter, or an inferred `let i = 0`) marks the name as unboxable in the type-check context. The match pattern binding sites in codegen_expr_match.c emit a boxed `HmlValue` declaration but never clear that mark, so codegen_expr_ident treats subsequent references as a native C primitive and emits `hml_val_i32(x)` on an HmlValue — producing a C compile error, or, if the prior native type happens to match, silent miscompilation. Clear the unboxable mark at every pattern binding site: * PATTERN_BINDING (`x => ...`) * PATTERN_TYPED (`x: i32 => ...`) * PATTERN_OBJECT shorthand (`{ x, y } => ...`) * PATTERN_OBJECT rest (`{ x, ...rest } => ...`) * PATTERN_ARRAY rest (`[a, b, ...tail] => ...`) This mirrors the existing treatment in `let`, `for` counter, and for-in codegen paths. Added tests/parity/language/match_stale_unbox covering all five binding sites.
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.
Same bug pattern as PRs #519 and #522: a prior same-named binding
(e.g.
for (let i = 0; ...)counter, or an inferredlet i = 0)marks the name as unboxable in the type-check context. The match
pattern binding sites in codegen_expr_match.c emit a boxed
HmlValuedeclaration but never clear that mark, so codegen_expr_ident treats
subsequent references as a native C primitive and emits
hml_val_i32(x)on an HmlValue — producing a C compile error, or, ifthe prior native type happens to match, silent miscompilation.
Clear the unboxable mark at every pattern binding site:
x => ...)x: i32 => ...){ x, y } => ...){ x, ...rest } => ...)[a, b, ...tail] => ...)This mirrors the existing treatment in
let,forcounter, andfor-in codegen paths.
Added tests/parity/language/match_stale_unbox covering all five
binding sites.