-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(codegen): test nested constructor patterns — three backends emitted the same guard #732
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -99,7 +99,23 @@ and gen_pattern_test scrut pat = | |||||||||||||
| match pat with | ||||||||||||||
| | PatWildcard _ | PatVar _ -> "true" | ||||||||||||||
| | PatLit lit -> Printf.sprintf "%s == %s" scrut (gen_lit lit) | ||||||||||||||
| | PatCon (id, _) -> Printf.sprintf "%s.tag == %S" scrut id.name | ||||||||||||||
| (* Sub-patterns must be tested, not discarded -- see codegen_deno.ml. Paths | ||||||||||||||
| mirror gen_pattern_bindings below: .value for arity 1, .values[i] else. | ||||||||||||||
| Lua indexes from 1, and the bindings walker uses the same expression, so | ||||||||||||||
| the two stay in step. *) | ||||||||||||||
| | PatCon (id, args) -> | ||||||||||||||
| let tag_test = Printf.sprintf "%s.tag == %S" scrut id.name in | ||||||||||||||
| let sub_tests = | ||||||||||||||
| match args with | ||||||||||||||
| | [] -> [] | ||||||||||||||
| | [single] -> [gen_pattern_test (scrut ^ ".value") single] | ||||||||||||||
| | many -> | ||||||||||||||
| List.mapi (fun i p -> | ||||||||||||||
| gen_pattern_test | ||||||||||||||
| (Printf.sprintf "%s.values[%d]" scrut i) p) many | ||||||||||||||
|
Comment on lines
+113
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Use Lua 1-based indexes in the recursive guard. Line 115 emits Proposed fix List.mapi (fun i p ->
gen_pattern_test
- (Printf.sprintf "%s.values[%d]" scrut i) p) many
+ (Printf.sprintf "%s.values[%d]" scrut (i + 1)) p) many📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| in | ||||||||||||||
| String.concat " and " | ||||||||||||||
| (tag_test :: List.filter (fun s -> s <> "true") sub_tests) | ||||||||||||||
| | PatTuple _ -> "true" (* arity match by structure, not tag *) | ||||||||||||||
| | PatRecord _ -> "true" | ||||||||||||||
| | PatAs (_, p) -> gen_pattern_test scrut p | ||||||||||||||
|
|
||||||||||||||
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.
🔴 HIGH RISK
Indexing mismatch: 'gen_pattern_test' uses 0-based indexing ('i'), but 'gen_pattern_bindings' in this file (line 146) uses 1-based indexing ('i + 1') for the '.values' array. In Lua, accessing index 0 will return
nil, causing guards to fail for multi-argument constructors. Usei + 1to align with Lua conventions and the existing binding logic: