Issue Details (XML | Word | Printable)

Key: JRUBY-2318
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: Steven Parkes
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

$~/Regexp.last_match lost when evaluation is inside a block

Created: 25/Mar/08 12:15 PM   Updated: 04/Jul/08 09:07 AM
Component/s: None
Affects Version/s: JRuby 1.1RC3
Fix Version/s: JRuby 1.1.2

Time Tracking:
Not Specified

File Attachments: 1. File get_match_data_inside_block.diff (0.7 kB)
2. File jruby_lm.rb (0.2 kB)

Issue Links:
Duplicate
 

Testcase included: yes


 Description  « Hide
When a regex is evaluated inside a block, it seems like $~/Regexp.last_match doesn't survive completion of the block. Code snippet which raises an exception under failure attached.

This affects both jruby 1.1RC3 and trunk r6337.

Behavior compared against 1.8.6 r15749 and 1.9 r15811.

Note this is extracted from autotest and is a blocker for me using autotest.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Fabio Kung added a comment - 25/Apr/08 01:09 PM
I've patched ZenTest to capture the matched data inside the block.
It's a quick fix until this issue gets resolved.

Charles Oliver Nutter added a comment - 25/Apr/08 02:06 PM
I can fix this by not doing a copy of the block's host frame, but that would break other things. I'm going to poke around MRI a bit to see where backrefs are actually supposed to be located.

Charles Oliver Nutter added a comment - 25/Apr/08 02:16 PM
This snippit, and a quick examination of the code, leads me to believe Ruby stores $~ and $_ in the topmost enclosing scope:
~/NetBeansProjects/jruby ➔ ruby -e "def foo; yield; end; 'foo' =~ /(foo)/; foo { 'bar' =~ /(bar)/ }; p \$~[0]"
"bar"

We need more specs for $~ and $_ for sure though, and we need to find a way around the frame copying.


Charles Oliver Nutter added a comment - 25/Apr/08 04:21 PM
Pretty sure now this is a side effect of the proc that's involved; since we clone the frame the proc is associated with (to keep it safe across threads, avoid it wiping out threads that are being used for other things). So if we can fix the cloning of frames in procs, we will probably have this.

I added some specs for $~ and $_.


Marcin Mielzynski added a comment - 09/May/08 12:55 PM
Revision 6654 still fails.

Charles Oliver Nutter added a comment - 13/May/08 05:14 PM
Fixed by framing changes in r6696, with a test added in r6698.

Fabio Kung added a comment - 26/May/08 10:43 PM
great Charles! I can confirm that ZenTest/autotest is working out-of-the-box.