Fix shift/pop in (&) prototype blocks + regex \b in character class#334
Merged
Conversation
log4perl-compatibility.md: - Updated test results: 6/73 failing (was 8/73), 18/700 subtests (was 26/700) - t/020Easy.t now passes all 21 tests (local $pkg::var bug fixed) - t/051Extra.t now passes all 11 tests - Reorganized remaining issues with clear status - Added progress tracking section cpan_client.md: - Added Phase 9b: Module::Build partial support - Updated jcpan capabilities documentation - Added summary statistics and completed phases list - Updated resolved questions list Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
Investigated jcpan -t Try::Tiny failures: - Found bug: shift returns undef in blocks captured via (&) prototype - @_ is populated correctly but shift does not work - DESTROY-related failures are expected (finally blocks) - caller() not reflecting set_subname is separate issue Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
When a block is captured via (&) prototype (e.g., Try::Tiny's catch), the parser was not setting isInSubroutineBody flag. This caused implicit shift/pop to default to @argv instead of @_. The fix saves and sets isInSubroutineBody(true) before parsing the block, then restores it afterward. This fixes Try::Tiny's t/basic.t which relies on $err = shift in catch blocks. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
63df801 to
a5c93b8
Compare
In Perl, \b inside a character class [...] represents a backspace character (0x08), but Java regex doesn't support this syntax directly. The fix converts \b to \x08 directly in the character class: - Remove the incorrectly pre-appended backslash from the StringBuilder - Append \x08 (hex notation for backspace) to the pattern - Don't double-increment offset (outer loop handles it) - Set first=false and lastChar=0x08 for proper range validation This approach correctly handles all cases: - [\b] -> [\x08] - matches backspace - [^\b] -> [^\x08] - matches anything except backspace - [\b-\n] -> [\x08-\n] - matches range from backspace to newline - [a\b] -> [a\x08] - matches 'a' or backspace Fixes JSON::PP and other modules that use patterns like ([\b]). Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
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
shift/popwithout explicit@_was defaulting to@ARGVinstead of@_when inside blocks captured via(&)prototype (e.g., Try::Tiny'scatch { })\binside character class[...]caused "Unmatched (" error - now correctly converts to\x08for Java regex compatibilityChanges
Bug Fix 1: PrototypeArgs.java
When parsing a block for
(&)prototype, the parser wasn't settingisInSubroutineBody. This caused implicitshift/popto default to@ARGVinstead of@_.Fix: Save and set
isInSubroutineBody(true)before parsing the block, restore afterward.Bug Fix 2: RegexPreprocessorHelper.java
In Perl,
\binside[...]means backspace (0x08), but Java regex doesn't support this.Fix: Convert
\bto\x08directly in the character class:[\b]->[\x08]- matches backspace[^\b]->[^\x08]- matches anything except backspace[\b-\n]->[\x08-\n]- preserves range semantics[a\b]->[a\x08]- matches 'a' or backspaceImpact on Try::Tiny
Impact on JSON::PP
Design Doc Updates
Test plan
makepasses all unit tests./jcpan -t Try::Tinyshows improvement (t/basic.t now passes)sub f (&) { $_[0] } f { shift }->('test')worksqr/([\b])/compiles and matches backspace correctlyGenerated with Devin