Skip to content

fix(dart): 4 func_start false-positive shapes (const ctors, bodyless ctors, class-header continuations, list-element calls) - #1494

Merged
squid-protocol merged 3 commits into
mainfrom
fix/dart-1479-func-start-false-positives
Aug 13, 2026
Merged

squid-protocol merged 3 commits into
mainfrom
fix/dart-1479-func-start-false-positives

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #1479 -- four distinct, confirmed func_start false-positive/false-negative shapes in dart:

  1. const ClassName.name(...) named constructors excluded entirely. The regex's blanket const-precedes-name exclusion (guarding against const x = value;) also blocked the legitimate constructor shape. Narrowed to only exclude const IDENT =/const IDENT;, letting const IDENT(/const IDENT.IDENT( through.
  2. Colon-initializer, no-braced-body constructors (Ctor(...) : super.x();) confused the brace-slicer into merging with the next method, losing the real name to detector.py's "Unknown_Block" fallback. Added a dart-specific paren/bracket/angle-depth-aware terminator scan recognizing : as an initializer list, terminated correctly by a following bodyless ; -- including when the initializer list has multiple comma-separated initializers (: a = b, assert(c);), which is normal Dart syntax and which an earlier version of this fix mishandled (see note below).
  3. Multi-line class header continuation lines (implements X { / extends Y<T> { on their own line) misfired as func_start. Excluded via a leading negative lookahead.
  4. Multi-line bare call-site invocations as list-literal elements still slipped past the existing Invocation Shield (func_start missing the args regex's 'Invocation Shield': bare call statements false-positive as function definitions (7 languages) #1221/csharp: detector.py's ';' vs '{'/'=>' terminator shield is fooled by a lambda arrow inside multi-line call arguments #1428). The same terminator scan rejects a match whose parameter list is immediately followed by a top-level ,.

Measured: found_functions 705->819, real_functions 705->884 (recall 79.8%->92.6%).

A note on process (independent verification caught a real bug in the first pass)

The Gemini/agy dispatch's first implementation of bug 2's fix reused the same terminator scanner for both the params-end check (which must stop at a top-level ,, needed for bug 4) and the colon-initializer-list scan (which must NOT -- Dart constructors routinely have multiple comma-separated initializers at depth 0, e.g. flutter/theme_data.dart's real ThemeData.raw: }) : b1 = x, b2 = y, assert(z);). That version silently rejected every multi-initializer constructor, including the actual repro case bug 1 was meant to fix. Caught during independent re-verification (the ThemeData.raw repro from the issue was still showing as "missing" post-fix), root-caused, and fixed directly by giving the initializer-list scan its own comma-skipping pass rather than reusing the comma-terminated one. Added a dedicated regression test (test_dart_slicer_multi_initializer_constructor) covering both the bodyless and body-bearing multi-initializer shapes.

extra_functions note

extra_functions rose slightly (281->286) as a side effect of finding more real constructors. Verified all 5 new "extra" names by hand against the real corpus (e.g. ErrorWidget.withDetails at flutter/framework.dart:5632, TextEditingController.fromValue at flutter/editable_text.dart:251) -- every one is a real dart constructor GitGalaxy now correctly extracts, which the accuracy tool's own tree-sitter ground truth (partially fixed by #1477/PR #1478) still doesn't resolve a matching name for in every shape. Not new false positives -- the audit tool's --regenerate regression gate correctly flagged this rise and required manual override with this explanation, per its own instructions.

One remaining gap filed separately as #1493 (not fixed here, out of scope): constructors with pathologically long parameter lists (hundreds of lines, e.g. ThemeData.raw itself) still aren't found, due to an unrelated search_limit bound in _slice_by_braces being too tight relative to the params-search's own larger lookahead budget.

Test plan

  • New/updated cases in tests/extraction/languages/test_dart.py (regex-level valid/invalid cases for all 4 bugs, plus dedicated slicer-level tests test_dart_slicer_bug_2_and_4 and test_dart_slicer_multi_initializer_constructor)
  • pytest tests/extraction/languages/test_dart.py tests/extraction/languages/test_dart_strict.py -- 183 passed
  • Pathological-input timing probe on both regex changes -- no ReDoS blowup
  • tree_sitter_accuracy_audit.py --lang dart --regenerate (manually applied after independently verifying the extra_functions rise was legitimate, per the tool's own "explain in the PR description" instruction), --summary-table regenerated
  • --all --ci clean across all 31 languages
  • crucible_check.py --mode both -- real drift confirmed as intended (e.g. flutter/events.dart's Public Exports count rose from finding more real constructors), blessed via --update --yes, re-ran to confirm PASS/PASS
  • audit_check.py --ci -- caught 2 real B023 (ruff) findings from the nested terminator-scan closing over per-iteration loop variables (safe_code/search_limit); fixed by binding them as function defaults rather than suppressing, then re-verified clean

…ctors, class-header continuations, list-element calls)

func_start was under- and over-matching real dart constructs in four distinct ways:

1. `const ClassName.name(...)` named constructors were unconditionally excluded by
   the regex's blanket const-precedes-name lookahead. Narrowed to only exclude
   `const IDENT =`/`const IDENT;` (variable declarations), letting `const IDENT(`/
   `const IDENT.IDENT(` (constructor calls) through.
2. Colon-initializer, no-braced-body constructors (`Ctor(...) : super.x();`) fell
   through to whatever brace happened to come next, merging with the following
   method and losing the real name to detector.py's "Unknown_Block" fallback.
   Added a dart-specific paren/bracket/angle-depth-aware terminator scan that
   recognizes `:` as starting an initializer list and correctly treats a
   following `;` as the real (bodyless) end -- including when the initializer
   list itself has multiple comma-separated initializers (`: a = b, assert(c);`,
   Dart's normal multi-initializer syntax), which a first attempt at this fix
   mishandled by reusing the same comma-terminated scanner used for bug 4 below.
3. Multi-line class header continuation lines (`implements X {` / `extends Y<T> {`
   on their own line) misfired as func_start matches. Excluded via a leading
   negative lookahead for `implements`/`with`/`extends` as the first token.
4. Multi-line bare call-site invocations used as list-literal elements
   (`ContextMenuButtonItem(\n  ...,\n),`) still slipped past the existing
   Invocation Shield. The same terminator scan now rejects a match whose
   parameter list is immediately followed by a top-level `,`.

found_functions 705->819, real_functions 705->884 (recall 79.8%->92.6%).
extra_functions rose slightly (281->286) -- verified the 5 new "extra" names
(e.g. ErrorWidget.withDetails, TextEditingController.fromValue) are real
constructors GitGalaxy now correctly finds that the accuracy tool's own
tree-sitter ground truth doesn't yet resolve a name for (same class of gap
#1477 partially closed) -- not new false positives.

Fixes #1479.

Co-authored-by: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol enabled auto-merge (squash) August 13, 2026 20:43
squid-protocol and others added 2 commits August 13, 2026 16:44
…art-false-positives

# Conflicts:
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
…landed first)

Parallel-PR conflict on the machine-generated golden master files -- resolved per
the documented pattern (checkout --theirs, then regenerate fresh on the merged
code rather than hand-resolving JSON conflicts). crucible_check.py --mode both
confirmed PASS/PASS after regenerating.

Co-authored-by: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol merged commit fcd40d2 into main Aug 13, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix/dart-1479-func-start-false-positives branch August 13, 2026 20:51
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant