fix(dataflow): grouped param wrapper gives every name the same paramIndex - #2502
Merged
Conversation
…ndex
extractParams incremented index once per child of the parameter list, so
a grammar node grouping multiple genuinely separate slots (Dart's
optional_formal_parameters for `{int times, bool loud}`) gave every name
inside it the same index instead of each getting its own. Adds
groupedParamTypes to unpack such wrappers into distinct slots, while
still sharing one index for true single-slot destructuring (JS/TS
object/array patterns) and skipping non-parameter siblings (default
value literals Dart's grammar attaches flat inside the group).
Closes #2358
docs check acknowledged
Impact: 4 functions changed, 2 affected
Contributor
Greptile SummaryThe PR corrects parameter-slot indexing for Dart grouped parameters while preserving shared indices for destructuring and positional indices after unnamed parameters.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Parameter-list child] --> B{Grouped parameter type?}
B -->|No| C[Extract names at current index]
C --> D[Always advance index]
B -->|Yes| E[Iterate grouped named children]
E --> F{Child yields names?}
F -->|Yes| G[Emit names and advance index]
F -->|No| H[Skip metadata/default-value child]
Reviews (2): Last reviewed commit: "fix(dataflow): unnamed parameter no long..." | Re-trigger Greptile |
Contributor
Codegraph Impact Analysis2 functions changed → 3 callers affected across 2 files
|
The previous commit's skip-empty-slot guard applied to every child of the parameter list, not just grouped ones — an unnamed C/C++ parameter (e.g. void f(int, int value)) yields zero names and was no longer consuming an index, shifting every later named parameter's position down by one. Scopes the skip to grouped slots only; an ordinary child still always consumes an index regardless of name count. docs check acknowledged Impact: 1 functions changed, 2 affected
Contributor
Author
|
@greptileai please re-review — pushed a fix for the unnamed-parameter regression you flagged. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Problem
extractParams(src/ast-analysis/visitor-utils.ts) incrementedindexonce per CHILD of the parameter list, not once per extracted name. Dart'soptional_formal_parameterswraps multiple genuinely separate parameter declarations in one child node ({int times, bool loud}), so bothtimesandloudgot the sameparamIndex.Fix
Added
groupedParamTypestoDataflowRulesConfig: when a child's type is in this set,extractParamsiterates that child's own named children as separate slots instead of treating the whole node as one slot. Set for Dart'soptional_formal_parameters.This is deliberately not a blanket "index per extracted name" change (the issue's own caution): true single-slot destructuring (JS/TS
function f({a, b})) must keep sharing one index acrossa/b, since both come from the same argument slot — verified via a new test locking that in.Also discovered Dart's grammar attaches a parameter's default-value literal (
= 1,= false) as a flat sibling inside theoptional_formal_parametersgroup, not nested inside itsformal_parameter— so the grouped-slot loop only consumes an index for a slot that actually yields a name, otherwise the literal siblings created off-by-N gaps.Simplified
extractDartParamNameby removing its now-dead recursiveoptional_formal_parametersbranch, sinceextractParamsno longer calls it on the group node directly.TS/WASM-only — the Rust engine has no Dart dataflow rules at all yet (tracked separately by #2359), so there's nothing to mirror there for this fix.
Follow-up filed
While verifying no other language relies on the old shared-index behavior, found Go's
func f(a, b int)hits the identical bug class in both engines (TS'sgo.tsand Rust'sextract_params_go) — already shipped, so lower risk tolerance and a differently-shaped fix. Filed as #2501, out of scope here.Closes #2358
Test plan
paramIndexvaluesparamIndex, non-destructured sibling gets the next onevitest runsuite (5272 passed, 328 files)tsc --noEmit,biome checkcargo test --release,cargo clippy -- -D warnings,cargo fmt --check(unaffected, confirmed clean)