Skip to content

fix: populate Dart class definitions' children with field declarations - #2569

Merged
carlos-alm merged 1 commit into
mainfrom
fix/issue-2475
Aug 18, 2026
Merged

fix: populate Dart class definitions' children with field declarations#2569
carlos-alm merged 1 commit into
mainfrom
fix/issue-2475

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

extractDartClassMembers's field-scanning loop looked for an identifier as a DIRECT child of the declaration node, but every real Dart field-declaration shape (final Foo x;, Foo x;, late Foo x;, Foo? x;, final Foo a, b;) nests it two levels deep: declaration -> initialized_identifier_list -> initialized_identifier -> identifier. Dart requires every field to carry a var/final/const/late/type modifier, so identifier is never a direct child of declaration — the loop silently found nothing for any real field, leaving a Dart class definition's children array permanently empty (confirmed empirically in the issue).

  • Fixes the WASM extractor's loop (src/extractors/dart.ts) to walk the correct path, mirroring handleDartFieldDeclTypeMap's identical traversal — including its handling of a comma-separated multi-field declaration (final Foo a, b; declares both a and b).
  • The Rust/native extractor (crates/codegraph-core/src/extractors/dart.rs) had no field-children collection mechanism at all — extract_dart_class_methods only ever pushed method Definitions, and the class's own Definition was always built with children: None. Added a new extract_dart_field_children helper and threaded a children: &mut Vec<Definition> accumulator through, using the existing opt_children helper for the final None-when-empty behavior.

Low severity, matching the issue's own framing — doesn't affect call resolution or the resolution-benchmark fixtures, only the children listing on Dart class definitions (e.g. for codegraph show ClassName-style output).

Test plan

  • New Rust unit tests in dart.rs (class_field_children module) — final field, plain/late field, comma-separated multi-field, methods-alongside-fields, no-fields-means-no-children
  • New TS unit tests in tests/parsers/dart.test.ts (#2475 describe block) — same coverage, WASM engine
  • Revert-verified: disabling each side's fix reproduces the pre-fix failures for the exact new tests added
  • npx tsc --noEmit -p ., npm run lint, full npm test (5472 passed)
  • cargo fmt -- --check, cargo clippy --lib -- -D warnings, cargo test --lib (1113 passed)

Closes #2475

extractDartClassMembers's field-scanning loop looked for an identifier
as a DIRECT child of the declaration node, but every real Dart field
shape (final Foo x;, Foo x;, late Foo x;, Foo? x;, final Foo a, b;)
nests it two levels deep (declaration -> initialized_identifier_list
-> initialized_identifier -> identifier) -- Dart requires a
var/final/const/late/type modifier on every field, so identifier is
never a direct child. This left every Dart class definition's
children array permanently empty.

Fixes the WASM extractor's loop to walk the correct path, mirroring
handleDartFieldDeclTypeMap's identical traversal (including its
handling of comma-separated multi-field declarations). The Rust/native
extractor had no field-children collection at all -- extract_dart_
class_methods only ever pushed method definitions -- so this adds a
new extract_dart_field_children helper and threads a children
accumulator through to the class's own Definition.

No doc updates needed -- internal extractor bug fix, no
language/feature/architecture surface change. docs check acknowledged.

Closes #2475

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

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR fixes Dart class metadata so field declarations appear as property children in both native and WASM extraction paths.

  • Traverses nested initialized-identifier lists, including comma-separated declarations.
  • Adds native accumulation of field children while preserving None for classes without fields.
  • Adds native and WASM regression coverage for common field forms and coexistence with methods.

Confidence Score: 5/5

The PR appears safe to merge, with the native and WASM implementations aligned for the field-declaration shapes covered by the change.

The changed extractors consistently populate class property children from nested initialized identifiers, preserve method output, and retain absent children for classes without fields; no concrete blocking or non-blocking defect remains.

Important Files Changed

Filename Overview
crates/codegraph-core/src/extractors/dart.rs Adds native field-child extraction and threads the accumulated children into Dart class definitions without disturbing method extraction.
src/extractors/dart.ts Replaces the ineffective direct-child scan with the nested initialized-identifier traversal used by Dart field declarations.
tests/parsers/dart.test.ts Adds WASM regression tests for final, plain, late, multi-field, mixed-member, and fieldless classes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Source["Dart class source"] --> Engine{"Extraction engine"}
  Engine --> Native["Native Rust extractor"]
  Engine --> Wasm["WASM TypeScript extractor"]
  Native --> List1["initialized_identifier_list"]
  Wasm --> List2["initialized_identifier_list"]
  List1 --> Fields1["property children"]
  List2 --> Fields2["property children"]
  Fields1 --> Class["Class Definition.children"]
  Fields2 --> Class
Loading

Reviews (1): Last reviewed commit: "fix: populate Dart class definitions' ch..." | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

1 functions changed3 callers affected across 1 files

  • extractDartClassMembers in src/extractors/dart.ts:99 (3 transitive callers)

@carlos-alm
carlos-alm merged commit 18cbe37 into main Aug 18, 2026
34 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2475 branch August 18, 2026 13:24
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 18, 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.

Dart: class field 'children' list never populated (dead identifier-scan in extractDartClassMembers)

1 participant