Skip to content

fix(perl): don't attribute an unrelated later block to a forward declaration - #1688

Merged
squid-protocol merged 6 commits into
mainfrom
fix/perl-1609-forward-decl-brace
Aug 15, 2026
Merged

squid-protocol merged 6 commits into
mainfrom
fix/perl-1609-forward-decl-brace

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #1609.

_slice_by_braces's generic Mode-B fallback searches forward from a
func_start match for the next { within a bounded window. A bodyless
forward declaration (sub GetASCII($);, ends in ;, no real definition
anywhere later in the file) has no { on its own declaration line, but the
window before the NEXT real sub/method keyword can contain an unrelated
{-opening block. Confirmed on language-crucible/data/perl/exiftool/exiftool:

sub GetASCII($);

$SIG{INT}  = 'SigInt';
$SIG{CONT} = 'SigCont';
END {
    Cleanup();
}

The generic fallback wrongly attributed END's 3-line body to GetASCII,
reporting a function that doesn't exist with a bogus body/LOC/args.

Fix

Added a perl-gated branch (mirrors objc-group-2's #1336 bodyless-prototype
rejection): scan forward tracking paren depth (perl legacy prototypes can
contain a semicolon internally, e.g. sub Options($$;@), so a naive
first-;-wins scan would misfire), and skip the match entirely if a ;
terminator is reached before a real { -- a genuine forward declaration,
out of func_start's scope, not a function with a body.

Verification

$ venv/bin/pytest tests/extraction/languages/test_perl.py tests/extraction/languages/test_perl_strict.py -q
112 passed

$ tree_sitter_accuracy_audit.py --lang perl
extra_functions   2 -> 1   (the GetASCII phantom is gone)
found_functions / args_exact_match unchanged for the dozens of correctly-
  handled forward declarations elsewhere in the same file
tree_sitter_accuracy_audit: no regressions.

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

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

Perl parser corpus (exiftool) -- the same file the issue's measurements came from.

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

squid-protocol and others added 3 commits August 15, 2026 16:36
…aration

_slice_by_braces's generic Mode-B fallback searches forward from a
func_start match for the next `{` within a bounded window. A bodyless
forward declaration (`sub GetASCII($);`, ends in `;`, no real definition
anywhere later in the file) has no `{` on its own declaration line, but the
window before the NEXT real sub/method keyword can contain an unrelated
`{`-opening block (confirmed on language-crucible's exiftool corpus: an
`END { Cleanup(); }` block a few lines after `sub GetASCII($);`). The
generic fallback wrongly attributed that unrelated block's body to
GetASCII, reporting a function that doesn't exist with a bogus body.

Added a perl-gated branch (mirrors objc-group-2's #1336 bodyless-prototype
rejection): scan forward tracking paren depth (perl legacy prototypes can
contain a semicolon internally, e.g. `sub Options($$;@)`, so a naive
first-`;`-wins scan would misfire), and skip the match entirely if a `;`
terminator is reached before a real `{` -- a genuine forward declaration,
out of func_start's scope, not a function with a body.

extra_functions 2 -> 1 (the GetASCII phantom is gone), found_functions/
args_exact_match unchanged for the dozens of correctly-handled forward
declarations elsewhere in the same file.

Fixes #1609

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…-decl-brace

# Conflicts:
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
#	tests/ruff_audit_baseline.json
@squid-protocol
squid-protocol enabled auto-merge (squash) August 15, 2026 20:41
…-decl-brace

# Conflicts:
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
#	tests/ruff_audit_baseline.json
@squid-protocol
squid-protocol merged commit a468b54 into main Aug 15, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix/perl-1609-forward-decl-brace branch August 15, 2026 21:15
@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.

perl: bodyless forward declaration can accidentally grab an unrelated nearby { as its body

1 participant