Fix pos() reset after study() to clear /g zero-length guard#176
Merged
Fix pos() reset after study() to clear /g zero-length guard#176
Conversation
In perl5, BEGIN blocks inside eval STRING can access outer lexical
variables with their runtime values. For example:
my @imports = qw(md5 md5_hex);
eval q{ use Digest::MD5 @imports }; # BEGIN sees @imports
Previously, BEGIN blocks would see empty variables because they execute
during parsing, before the eval class is instantiated with runtime values.
Solution:
1. Modified evalStringHelper() to accept runtime values array
2. Store runtime values in ThreadLocal during eval STRING parsing
3. In SpecialBlockParser, alias special globals to runtime objects
4. Global variable keys don't include sigil (use "pkg::arr" not "pkg::@arr")
5. Added backwards-compatible evalStringHelper(code, evalTag) overload
This fixes Test::More use_ok() pattern which relies on this behavior.
Note: control_flow.t test 11 is currently failing with "Can't find label"
error. This needs further investigation as it may be a separate issue.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
This PR includes two commits:
Context
re/regexp.t regressed by 3 subtests (1097, 1110, 1111) involving
study $subject; pos($subject)=0;followed by/glookahead matches.Fix
Clear the zero-length match guard state when assigning to
pos($str), so an explicit pos reset behaves like perl5 and doesn't get blocked by the repeated zero-length match protection.Verification
makeperl5_t/t/re/regexp.t: the 3 regressed subtests are now passing (not-ok count drops 427 -> 424).