Skip to content

fix(dart): stop treating try/finally blocks as function declarations (#1622) - #1673

Closed
uuzzrm wants to merge 3 commits into
squid-protocol:mainfrom
uuzzrm:fix/dart-try-finally-phantoms
Closed

fix(dart): stop treating try/finally blocks as function declarations (#1622)#1673
uuzzrm wants to merge 3 commits into
squid-protocol:mainfrom
uuzzrm:fix/dart-try-finally-phantoms

Conversation

@uuzzrm

@uuzzrm uuzzrm commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What & why

Closes #1622.

Dart's try and finally keywords at line start were misdetected as phantom zero-arg function declarations: the func_start regex's negative-lookahead keyword exclusions covered class|mixin|enum|extension|typedef|if|for|while|switch|catch|case|when|assert|return|throw|new|var|final|const but never try or finally — so try { / finally { matched as a function literally named "try"/"finally". Confirmed via the issue's repro against language-crucible/data/dart/flutter/*.dart: 38 spurious "try" rows in function_data, ~9% of dart's remaining func_start false-positive rate.

The fix

Add try|finally to the keyword-exclusion lookaheads in all three func_start alternatives (6 exclusion sites in gitgalaxy/standards/language_standards.py). A real method named tryMethod still matches; only the reserved keywords are rejected.

Measured effect (tree-sitter accuracy audit, pinned corpus)

metric baseline with fix
dart found_functions 1340 1340 (unchanged)
dart extra_functions 186 149 (-37 phantom try/finally functions removed)

Zero recall loss, no regressions. Golden-master fixtures re-blessed via update_golden_master.py (both modes); the drift is confined to dart entries plus the usual sub-epsilon float drift from the shared spatial layout recomputing on the changed graph.

Test plan

  • 4 new invalid cases in tests/extraction/languages/test_dart.py: try {, finally {, indented variants.
  • pytest tests/extraction/languages/test_dart.py test_dart_strict.py → 190 pass.
  • tree_sitter_accuracy_audit.py --lang dart → no regressions (baseline re-blessed: extra 186→149).
  • ruff_audit.py --ci: no new findings; dead-key-audit/ast-accuracy-audit clean.

uuzzrm and others added 3 commits August 15, 2026 12:40
…quid-protocol#1631)

func_start's colon-annotated-arrow branch cannot distinguish a real
arrow-function property from a parameter's function-type annotation --
both are `IDENT: (...) => ...` on the surface. A nested parameter
(`f: (a: A) => B` inside an interface member's own signature, e.g.
fp-ts pipeable.ts's `f`/`g` phantoms) is always the first thing after
an already-open parameter list, so its line is directly preceded by
`(`; an object-literal arrow property is never (its enclosing `{` is).
Dropping line-anchored matches whose preceding non-whitespace char is
`(` removes the phantom parameter annotations without touching real
arrow-function properties.

Measured against language-crucible/data/typescript:
- extra_functions: 299 -> 275 (24 phantom parameter annotations removed)
- found_functions: 1876 -> 1876 (zero recall loss)
- args_exact_match: 1796 -> 1796 (unchanged)
- javascript: no regressions (found 599, extra 11 unchanged)

Golden masters re-blessed via update_golden_master.py (the phantom
function entries are gone from the corpus snapshots); both crucible
modes pass. Closes squid-protocol#1631.

Signed-off-by: Ruiming Zhao <uuzzrm@gmail.com>
Resolves the generated-file conflict from merging origin/main (which had
just picked up squid-protocol#1655's typescript brace-less-arrow fix) into this PR's
branch -- standard parallel-PR conflict resolution: took main's version of
the generated files, then regenerated fresh on the merged code.
@uuzzrm
uuzzrm requested a review from squid-protocol as a code owner August 15, 2026 19:54
@squid-protocol

Copy link
Copy Markdown
Owner

Same fix, independently arrived at -- both add `try|finally` to the same 6 occurrences of the exclusion list. This is already up as #1664 (open, same diagnosis and fix shape), so closing this one as a duplicate to avoid two competing PRs on the same regex region. Nothing wrong with this PR -- just landed a few minutes behind.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dart: try/finally keywords misdetected as zero-arg function declarations

2 participants