Repository navigation
fix(dart): extend Invocation Shield to closure-typed call arguments - #1701
Merged
Merged
Conversation
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
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1624.
A function call whose final argument is itself a closure/callback literal
(
identifier(args, (ParamType name) {) reads structurally like a functionsignature followed by its body-open brace (
name(params) {), defeating theexisting Invocation Shield (#1221, #1428, #1479). Root cause: the params-list
scan (
_find_balanced_endtracking only()) is brace-blind -- it walksstraight through a closure argument's own
{...}body and stops at thecall's real closing
), making the trailing;look exactly like alegitimate bodyless-constructor terminator.
Real corpus repro shapes (
language-crucible/data/dart/flutter/), allpreviously phantom
function_datarows: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-openbrace (
(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 nextsignificant char to be
(at all, so getters (no parameter list) neverreach the scan.
Verification
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 bothblessed via--update --yes(expectedcascading drift).
audit_check.py --ciclean.Type of change
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]