Repository navigation
Description
Summary
Investigating the dart tri-comparison ledger's two function/existence shapes
(agree[gitgalaxy]_vs[tree_sitter], 37 occurrences; agree[tree_sitter]_vs[gitgalaxy], 18
occurrences) against the real language-crucible/data/dart corpus (7 Flutter framework files,
~40K lines) surfaced two related false-positive bugs in dart's func_start regex
(gitgalaxy/standards/language_standards.py), both confined to the regex's "zero-prefix"
alternative (no modifier, no return-type prefix required before the name).
Bug 1: Dart 3 switch-expression arms matched as getters
Dart's real grammar has no parameterless => expr construct without an explicit get keyword —
but the zero-prefix branch's trailing lookahead accepted a bare => unconditionally. Since Dart 3
switch-expression arms have exactly this shape (Pattern => result,), they false-positive-matched
as getter definitions:
// flutter/editable_text.dart:2117
TargetPlatform.windows => true, // matched as a getter named "TargetPlatform.windows"
// flutter/framework.dart:193-194
StatefulElement(:final T state) => state, // matched as "StatefulElement"
_ => null, // matched, name-extraction fell back to "Unknown_Block"A corpus-wide heuristic scan found ~47 candidate matches of this shape across the 7-file corpus.
Bug 2: call statements with a lambda argument matched as function definitions
The same branch's paren-lookahead used a naive, non-balanced-paren check (\([^)]*\)) instead of
the balanced-paren pattern already used elsewhere in this same regex (and in the sibling args
rule). [^)]* cannot track nesting, so it stops at the first ) it finds — which, for a call
with a lambda argument, is the lambda's own closing paren, not the outer call's. Whatever followed
that inner paren (often => from the lambda body, or { from a lambda block) then satisfied the
lookahead, misdetecting the whole call as a function signature:
// flutter/framework.dart:3756
visitChildren((Element child) { // matched as if defining "visitChildren"
child.reassemble();
});
// flutter/object.dart:592
clipRectAndPaint(offsetClipRect, clipBehavior, offsetClipRect, () => painter(this, offset));
// matched as "clipRectAndPaint"
// flutter/framework.dart:3363
keyStringCount.update(key, (int value) => value + 1); // matched as "keyStringCount.update"This was the larger contributor by far — a full corpus-wide before/after diff (see Verification
below) found 126 false-positive matches removed across all 7 files, nearly all of this shape
(setState(() {...}), .forEach/.where/.sort/.removeWhere/.update/.putIfAbsent calls
with lambda arguments, and bare self-calls like visitChildren(...)/updateConfig(...)).
Fix
Both bugs live in the same branch, fixed together:
- The bare-
=>lookahead alternative is now gated behind the sameget-group conditional
((?(getC)=>|(?!))) already used for the bare-;case in this exact regex — grammatically
correct, since every real no-paren=> exprin Dart requiresget. - The paren-lookahead now uses the same balanced-paren pattern (
\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))
theargsrule and this regex's own return-type-prefix groups already use, plus a
(?!\s*:)guard rejecting Dart 3's object-destructuring pattern syntax (Pattern(:field) =>),
which is never a valid parameter list.
Verification
- Full corpus (7 files,
language-crucible/data/dart) raw-regex before/after diff: 1875 → 1750
matches (-126 false positives, +1 genuine recall fix — see below). Every one of the 126 removed
matches was manually spot-checked (dotted call receiver, or a multi-line call ending);, or a
switch-expression arm) — none were real function/getter definitions. - Side effect: also fixes a previously-
xfail'd known gap intest_dart.py
(print('void main() {');— a string literal containing text that looks like a function
header). The balanced-paren tracking now correctly treats the embeddedmain()as a nested
pair instead of mistaking it for the call's own closing paren, so the fake{inside the string
is never reached. - Bonus recall fix:
EditableText's own multi-line, many-named-parameter constructor
(flutter/editable_text.dart:829) now matches too — the old naive paren check landed on an
unrelated)deep inside the parameter list and never found the real signature end; the
balanced-paren fix finds it correctly. tests/extraction/languages/test_dart.py/test_dart_strict.py: 196 passed, 1 skipped, 4 xfailed.crucible_check.pyagainst the full ~80-repo corpus: see linked PR for the diff.
Follow-up
A related, smaller false positive (multi-line class headers with with/implements clauses
spanning several lines getting absorbed as a phantom function's "return-type prefix", e.g.
implements AutofillClient { matching as a function named AutofillClient) was found in the same
investigation but is not fixed here — the straightforward fix (excluding implements/with/
extends from the return-type-prefix token vocabulary) also broke a much more common, legitimate
pattern: generic method type-parameter bounds (static Future<T?> pushNamed<T extends Object?>(...)),
which also uses extends. Filed as a separate follow-up issue along with several other recall gaps
found in the same pass (dotted static getter return types, generic getter return types not
surviving to the final pipeline output, private named constructors).
🤖 Filed with Claude Code
Activity
fix(dart): count named / optional-positional parameter groups in args (…