A041 DuplicateLocalName#237
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #217
Confidence Score: 4/5
Safe to merge; the new rule correctly replaces a codegen panic with a structured diagnostic, and all collision asserts in wasm-codegen are now properly attributed to A041.
The rule implementation faithfully mirrors
pre_scan_locals' DFS descent, the per-body accumulator is fresh and correctly scoped, and the first-location tracking behaves as the triple-duplicate test verifies. The only finding is a minor test-helper redundancy inrules_a041.rswhere the same analysis pipeline is invoked twice for the same source string within a single test.tests/src/analysis/rules_a041.rs — the triple-duplicate test runs the analysis pipeline twice unnecessarily.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Source file] --> B[Type Checker] B -->|"rejects ancestor/parameter shadowing (VariableShadowed)"| ERR1[Type error] B -->|"accepts sibling-block reuse (different scopes)"| C[Analysis pass] C --> D{A041: DuplicateLocalName} D -->|"first_seen map: name not yet seen"| E[Record first_location] D -->|"first_seen map: name already seen"| F["Emit diagnostic\n(location = duplicate site,\nfirst_location = first site)"] F --> ERR2[Analysis error - stops pipeline] E --> G{More declarations?} G -->|Yes| D G -->|No| H[wasm-codegen] H --> I[pre_scan_locals DFS] I -->|"defense-in-depth assert (A041 invariant)"| J{Name already in locals_map?} J -->|"No (expected path)"| K[Assign WASM local index] J -->|"Yes (should never happen after A041)"| L[assert! panic] K --> M[Compiled WASM output]%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[Source file] --> B[Type Checker] B -->|"rejects ancestor/parameter shadowing (VariableShadowed)"| ERR1[Type error] B -->|"accepts sibling-block reuse (different scopes)"| C[Analysis pass] C --> D{A041: DuplicateLocalName} D -->|"first_seen map: name not yet seen"| E[Record first_location] D -->|"first_seen map: name already seen"| F["Emit diagnostic\n(location = duplicate site,\nfirst_location = first site)"] F --> ERR2[Analysis error - stops pipeline] E --> G{More declarations?} G -->|Yes| D G -->|No| H[wasm-codegen] H --> I[pre_scan_locals DFS] I -->|"defense-in-depth assert (A041 invariant)"| J{Name already in locals_map?} J -->|"No (expected path)"| K[Assign WASM local index] J -->|"Yes (should never happen after A041)"| L[assert! panic] K --> M[Compiled WASM output]Comments Outside Diff (1)
tests/src/analysis/rules_a041.rs, line 626-633 (link)count_a041(source)anda041_diags(source)both run the full parse → type-check → analyze pipeline on the samesourcestring. Theassert_eq!(count_a041(source), 2, …)assertion is then immediately re-checked asassert_eq!(diags.len(), 2, …)from the result of the second run, so the first call — and its pipeline invocation — is dead work. Callinga041_diagsonce and asserting on.len()is sufficient.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (1): Last reviewed commit: "A041 DuplicateLocalName" | Re-trigger Greptile