Repository navigation
Description
Summary
Found while verifying #1517/#1518's perl args-counting fix (PR pending): mojo/Template.pm::_line is a real, tiny 4-line sub (lines 236-239):
sub _line {
my $name = shift->name;
$name =~ y/"//d;
return qq{#line @{[shift]} "$name"};
}But the committed golden master (tests/golden_master_audit.json, confirmed present on main BEFORE any of #1517/#1518's changes -- this is not a regression from that work) records _line spanning lines 236-672 (437 LOC, all the way to the end of the file, past _trim/_wrap/_compile/several other real subs, into the POD documentation section). This is a func_start/block-slicing bug, not an args-counting bug -- #1517/#1518 just made its damage more visible: Input Parameters for this phantom-huge block went from a plausible-looking 1 to a clearly-wrong 13 once the args counter started summing every shift/my (...) = @_ occurrence across the whole (wrongly huge) block, instead of only finding the first one.
Confirmed repro
Fresh, uncached galaxyscope scan of just this one file reproduces it:
{'func_name': '_line', 'args': 13, 'loc': 437}
But calling StructuralExtractor("perl", ...)._function_slice() directly on the same raw file content gives the CORRECT span:
_line 236 239 4 # correctSo the bug is NOT in _function_slice itself (confirmed via direct unit-level call) -- it must be introduced somewhere else in the full pipeline between raw file content and _function_slice's input (most likely prism.py's comment/string-shielding stage, since _line's body contains qq{#line @{[shift]} "$name"} -- a qq{...} custom-delimited quote-like operator whose delimiter ({/}) collides with an interpolated @{[shift]} "baby cart" expression also containing a {/} pair. This is exactly the kind of delimiter-collision shape that's broken prism.py's shielding before). Not confirmed as the root cause, just the most likely candidate based on the code shape -- whoever picks this up should verify by diffing prism.py's shielded output for this file against the raw content around line 236-240.
I did NOT find a caching explanation (checked for a stale incremental-scan cache reusing old state -- the repro above used a fresh output directory and a file copied fresh into an empty scratch directory, so it's not state_rehydrator.py serving stale data).
Scope
Not fixed here -- filed as a follow-up while working on a different (args-counting) fix, per repo convention. This affects func_start block-boundary accuracy for at least this one real-world shape; unknown how many other perl files in the corpus have the same swallowed-block issue (only noticed because _line's tiny real size made the wrong 437-LOC span glaring in the crucible diff -- a function whose real vs. wrong size were closer wouldn't have been as obviously wrong).
Activity
fix(shell,perl): args-counting for languages with no formal parameter…
squid-protocol commentedon Aug 14, 2026
Root cause now fully confirmed (this session's investigation), and it's different from the original hypothesis -- not a brace-delimiter collision inside
qq{...}'s interpolation, but a much more general bug inprism.py's_strip_single_line_comments: perl's#-to-end-of-line comment stripper has no awareness of perl's quote-like operators (qq{...},q{...}, etc.) OR of/regex/literals (bare or keyword-prefixed:m/.../,s/.../.../, etc.) -- any#character that appears as literal CONTENT inside either of those, on the same line, gets misread as a real comment start, and everything from that#to end-of-line is stripped out ofcode_streambeforedetector.pyever sees it.Confirmed via THREE separate real corpus functions (not just
_line), all inlanguage-crucible/data/perl(sibling checkout):mojo/Template.pm::_line(the original case):return qq{#line @{[shift]} "$name"};-- the#lineright afterqq{is real quote-op content (a perl#linedirective template), but prism.py's stripper doesn't know it's insideqq{...}and treats the#as a comment start, deleting#line @{[shift]} "$name"};and desyncing everything downstream through end of file.exiftool/exiftool::FilterArgfileLine(line 4893, real 23-line function):if ($arg =~ /^#/) { # comment lines begin with '#'-- the bare/^#/regex literal (checking "does the string start with#") has its OWN#misread as a comment start, again with no quote-op keyword prefix at all (just=~ /.../), stripping the rest of that line and desyncing the function's body -- confirmed measured as swallowing 1048 lines (loc 1048 instead of ~23), which also swallows the real definition ofReadStayOpen(line 4922) entirely out of GitGalaxy's output.spamassassin/Makefile.PL::MY::dist(line 972):next if $line =~ /^\s*#/;-- same mechanism, same bare-regex-with-embedded-#shape.Reproduction: load any of the above files, call
Prism(LEXICAL_FAMILY_HEURISTICS, LANGUAGE_DEFINITIONS).split_streams(content, 'perl')['code_stream'], and diff against the raw source around the cited line -- the text after the embedded#is missing/blank incode_stream, confirming prism.py (not detector.py) is where the text is actually lost.Verified NOT the same bug as #1606 (POD-apostrophe, already fixed) or #1607 (legacy-prototype args, already fixed) -- both of those are
detector.py-level (_build_brace_safe_stream) and already shipped. This one is upstream inprism.py, beforedetector.pyever runs.Two sub-cases of the SAME general shape were separately fixed this session, in
detector.py's_build_brace_safe_stream(NOT prism.py, so they don't fix_line/FilterArgfileLineabove, which are prism.py-level):\{/\}inside an unshielded/regex/literal desyncing the brace-depth counter (exiftool/exiftool::SuggestedExtension, was swallowing 1206 lines instead of 57) -- fixed by blanking\{/\}globally before brace-depth counting.y/"//d) containing a bare"/'in its own content false-pairing with an unrelated later quote -- fixed by recognizing keyword-prefixed/.../quote-ops (m/,s/,y/,tr/, etc.) and shielding them before the generic quote-shield runs.What's needed to close #1517 for real (not attempted this session -- prism.py's
_strip_single_line_commentsis shared across the whole "line_exclusive" language family, ~20 languages, with a documented history of subtle regressions -- see that method's own docstring citing #1184/#1193/#1271 -- so this needs its own careful, well-tested PR, not a rushed addition): teach_strip_single_line_comments, gated strictly tolang_id == "perl", to mask two shapes per-line (bounded, no cross-line state, same conservative philosophy the method already uses) BEFORE running its#-delimiter search: (a)qq{...}/q{...}/etc. brace-delimited quote-ops (can likely reuse/adapt the bounded balanced-brace approachdetector.py's_build_brace_safe_streamalready has for this), and (b)/regex/literals -- both keyword-prefixed (m/,s/, etc., can likely adapt the slash-terminator scandetector.pyalready added this session) AND bare ($x =~ /.../,if ($x =~ /.../ ), no keyword prefix, which is the more common real-world form and wasn't attempted anywhere this session since disambiguating a bare/as regex-open vs. division is the genuinely hard, ambiguous part -- likely needs a preceding-token heuristic:/immediately preceded by=~,!~,(,,,;,{,&&,||, or a keyword likeif/unless/while/split/grep/map/returnis very likely a regex open; preceded by an identifier/number/)/]is very likely division).Once fixed, this is very likely to close most/all of perl's remaining func_recall gap -- all 3 confirmed cases above are currently the ONLY "missing function" entries left in the tree-sitter-accuracy baseline for perl (down from ~126 before this session's #1606/#1607/#1608 fixes).
fix(perl): shield-corruption and legacy-prototype fixes for tree-sitt…