Skip to content

fix(dataflow): Dart arrow-body functions never record an implicit return - #2498

Merged
carlos-alm merged 1 commit into
mainfrom
fix/issue-2356-dart-arrow-body-return
Aug 14, 2026
Merged

fix(dataflow): Dart arrow-body functions never record an implicit return#2498
carlos-alm merged 1 commit into
mainfrom
fix/issue-2356-dart-arrow-body-return

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • tree-sitter-dart represents an arrow-bodied function (int f() => x + 1;) as function_body containing the expression DIRECTLY — no return_statement node at all. dataflowDart's returnNode: 'return_statement' never matched, so arrow-bodied functions never recorded a returns entry — a distinct semantic gap from Dart: function_signature/method_signature never contains its own body — breaks per-function complexity/dataflow analysis #2182's sibling-body fix (an implicit return via => isn't modeled as a return at all).
  • Adds a new implicitReturnBodyNode/blockBodyNode config pair to DataflowRulesConfig: when a configured node's only named child is not the block type, that child is recorded as an implicit return the same way handleReturn already does for a real return_statement (it only ever reads namedChildren[0], so it works unmodified regardless of the wrapper node's actual type).
  • Enabled only for Dart (implicitReturnBodyNode: 'function_body') — no other language sets this field, so this is purely additive with zero behavior change elsewhere.
  • Rust's native engine has no Dart dataflow rules at all yet (tracked separately as follow-up: Rust engine needs DartDataflowRules to match TS's now-fixed dataflowDart #2359), so this is legitimately TS/WASM-only — no dual-engine parity gap for this specific fix.
  • While verifying, found that calls nested inside a return/other expression are never tracked at all for Dart (argFlows stays empty even for an ordinary block-bodied function) — a separate, pre-existing gap, unrelated to this fix. Filed as follow-up: Dart dataflow — calls nested inside a return/other expression are never tracked #2497.

Test plan

  • New tests in tests/parsers/dataflow-dart.test.ts: implicit return from a top-level arrow-bodied function, from an arrow-bodied class method, and a check that a block-bodied function isn't double-counted
  • Full test suite: 328 files / 5263 tests passed
  • npm run lint clean
  • diff-impact — contained (1 function changed, 1 transitive caller)

Closes #2356

tree-sitter-dart represents an arrow-bodied function (int f() => x + 1;)
as function_body containing the expression DIRECTLY — no
return_statement node at all. dataflowDart's returnNode:
'return_statement' never matched, so arrow-bodied functions never
recorded a returns entry, independent of #2182's sibling-body fix
(this is a distinct semantic gap: an implicit return via => isn't
modeled as a return at all).

Adds a new implicitReturnBodyNode/blockBodyNode config pair to
DataflowRulesConfig: when a configured node's only named child is not
the block type, that child is recorded as an implicit return the same
way handleReturn already does for a real return_statement (it only
ever reads namedChildren[0], so it works unmodified regardless of the
wrapper node's actual type). Enabled only for Dart
(implicitReturnBodyNode: 'function_body') — no other language sets
this, so this is purely additive.

Rust's native engine has no Dart dataflow rules at all yet (tracked
separately as #2359), so this is legitimately TS/WASM-only — no dual-
engine parity gap for this specific fix.

While verifying, found calls nested inside a return/other expression
are never tracked at all for Dart (argFlows stays empty even for an
ordinary block-bodied function) — a separate, pre-existing gap,
unrelated to this fix. Filed as #2497.

Closes #2356

Impact: 3 functions changed, 1 affected
@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds Dart expression-bodied function support to the TypeScript/WASM dataflow analyzer.

  • Extends DataflowRulesConfig with configurable implicit-return and block-body node types.
  • Configures Dart function_body nodes to produce return entries when their sole named child is an expression rather than a block.
  • Adds coverage for top-level functions, class methods, and block-body duplicate prevention.

Confidence Score: 5/5

The PR appears safe to merge with no concrete correctness or security issues identified.

The Dart-only configuration recognizes expression-bodied functions without changing other language rules, while the visitor still traverses expression children and avoids treating block bodies as implicit returns.

Important Files Changed

Filename Overview
src/ast-analysis/visitors/dataflow-visitor.ts Adds narrowly configured implicit-return dispatch while preserving traversal of nested expression nodes.
src/ast-analysis/rules/b2.ts Enables implicit-return body recognition only for Dart and retains block as the statement-body discriminator.
src/ast-analysis/shared.ts Adds inert defaults for the new dataflow configuration fields, leaving other languages unchanged.
src/types.ts Documents and types the new implicit-return configuration contract consistently with its defaults and use.
tests/parsers/dataflow-dart.test.ts Covers top-level and method arrow bodies plus prevention of duplicate returns for block bodies.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Dart function_body] --> B{Exactly one named child?}
  B -->|No| E[Continue normal child traversal]
  B -->|Yes| C{Child type is block?}
  C -->|Yes| E
  C -->|No| D[Record child expression as implicit return]
  D --> E
Loading

Reviews (1): Last reviewed commit: "fix(dataflow): dart arrow-body functions..." | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

1 functions changed1 callers affected across 1 files

  • dispatchDataflowNode in src/ast-analysis/visitors/dataflow-visitor.ts:481 (1 transitive callers)

@carlos-alm
carlos-alm merged commit 871d2fc into main Aug 14, 2026
27 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2356-dart-arrow-body-return branch August 14, 2026 09:36
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

follow-up: Dart dataflow — arrow-body (=>) functions never record an implicit return

1 participant