Skip to content

fix(dart): extend Invocation Shield to closure-typed call arguments - #1701

Merged
squid-protocol merged 4 commits into
mainfrom
fix/dart-1624-closure-invocation-shield
Aug 15, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
fix/dart-1624-closure-invocation-shield

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #1624.

A function call whose final argument is itself a closure/callback literal
(identifier(args, (ParamType name) {) reads structurally like a function
signature followed by its body-open brace (name(params) {), defeating the
existing Invocation Shield (#1221, #1428, #1479). Root cause: the params-list
scan (_find_balanced_end tracking only ()) is brace-blind -- it walks
straight through a closure argument's own {...} body and stops at the
call's real closing ), making the trailing ; look exactly like a
legitimate bodyless-constructor terminator.

Real corpus repro shapes (language-crucible/data/dart/flutter/), all
previously phantom function_data rows:

visitChildren((Element child) { ... });
setState(() { ... });
configProvider.updateConfig((SemanticsConfiguration config) { ... });
_addAction(action, (Object? args) { ... });

Fix

Added _dart_is_closure_invocation: scans the parameter-list span for a {
at paren-depth 1 (directly inside the outer call's parens) and checks what
immediately precedes it. Preceded by ) -> a closure literal's own body-open
brace ((params) { / () {) -> this is a call, not a declaration, skip it.
Preceded by ( or , -> Dart's legitimate named-parameter block
(foo(a, {int x = 1})) -> untouched. A leading guard requires the very next
significant char to be ( at all, so getters (no parameter list) never
reach the scan.

Verification

$ venv/bin/pytest tests/extraction/languages/test_dart.py tests/extraction/languages/test_dart_strict.py tests/core_engine/test_detector.py -q
318 passed, 1 skipped, 5 xfailed

$ tree_sitter_accuracy_audit.py --lang dart
extra_functions   78 -> 30   (was the largest remaining false-positive bucket)
found_functions / args_exact_match unchanged
tree_sitter_accuracy_audit: no regressions.

$ tree_sitter_accuracy_audit.py --all --ci
31 language(s) checked, all OK.

Cross-checked the 4 named repro shapes against real corpus files: every
remaining hit for those names now corresponds 1:1 to a genuine declaration
elsewhere in the file; configProvider.updateConfig (zero real declarations,
only call sites) now produces zero hits at all.

crucible_check.py --mode both blessed via --update --yes (expected
cascading drift). audit_check.py --ci clean.

Type of change

  • Bug fix
  • Parsing or engine logic (detector.py)

Differential Scan target

Dart parser corpus (flutter) -- the same files the issue's measurements came from.

Co-Authored-By: Claude Sonnet 5 [email protected]

squid-protocol and others added 4 commits August 15, 2026 17:13
A function call whose final argument is itself a closure/callback literal
(`identifier(args, (ParamType name) {`) reads structurally like a function
signature followed by its body-open brace (`name(params) {`), defeating the
existing Invocation Shield (#1221, #1428, #1479). Root cause: the params-list
scan (`_find_balanced_end` tracking only `()`) is brace-blind -- it walks
straight through a closure argument's own `{...}` body and stops at the
call's real closing `)`, making the trailing `;` look exactly like a
legitimate bodyless-constructor terminator.

Added `_dart_is_closure_invocation`: scans the parameter-list span for a `{`
at paren-depth 1 (directly inside the outer call's parens) and checks what
immediately precedes it. Preceded by `)` -> a closure literal's own body-open
brace (`(params) {` / `() {`) -> this is a call, not a declaration, skip it.
Preceded by `(` or `,` -> Dart's legitimate named-parameter block
(`foo(a, {int x = 1})`) -> untouched. A leading guard also requires the very
next significant char to be `(` at all, so getters (no parameter list) never
reach the scan.

Real corpus repro shapes (language-crucible/data/dart/flutter/), all
previously phantom function_data rows, now correctly excluded:
  visitChildren((Element child) { ... });
  setState(() { ... });
  configProvider.updateConfig((SemanticsConfiguration config) { ... });
  _addAction(action, (Object? args) { ... });

extra_functions 78 -> 30 (was the largest remaining false-positive bucket,
per the issue's own estimate of ~80+ instances), found_functions/
args_exact_match unchanged.

Fixes #1624

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…-invocation-shield

# Conflicts:
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
#	tests/ruff_audit_baseline.json
@squid-protocol
squid-protocol merged commit 5fc2693 into main Aug 15, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix/dart-1624-closure-invocation-shield branch August 15, 2026 21:30
@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

Development

Successfully merging this pull request may close these issues.

dart: call sites with closure-literal trailing arguments misdetected as function definitions

1 participant