Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

$/ broken for replacement inside for loop #3560

Closed p6rt closed 8 years ago

p6rt commented 9 years ago

Migrated from rt.perl.org#123005 (status was 'resolved')

Searchable as RT123005$

p6rt commented 9 years ago

From @raydiak

my $a = 'a'; s/(.)/$0/ for $a; $a.perl.say;

Expected result​: "a" Actual result​: ""

This is perl6 version 2014.09-227-g3448cb1 built on MoarVM version 2014.09-54-g03ac9a7

p6rt commented 9 years ago

From vdheuvel@heuvelhlt.nl

Version Perl6 2014.09 built on MoarVM 2014.09 Windows 7.

Code

my $string = "ACCB"; for $string {   s/A (\<-[B]>*) B/$0/;   say $_; }

produces nog output. However, the next fragment produces "CC" as expected.

my $string = "ACCB"; for $string {   my $mid;   s/A (\<-[B]>*) { $mid = $0 } B/$mid/;   say $_; }

-- Theo van den Heuvel Van den Heuvel HLT Consultancy Malden, The Netherlands   +31 24 3736356   +31 625492788

p6rt commented 9 years ago

From @raiph

See also​:

​118705​: [BUG] s/// doesn't update $/ inside for loop

​123005​: [BUG] $/ broken for replacement inside for loop

p6rt commented 9 years ago

From @raiph

See also​:

​118705​: [BUG] s/// doesn't update $/ inside for loop

​123323​: $0 in substitution

p6rt commented 9 years ago

From @usev6

I added two tests to S04-statements/for.t with commit https://github.com/perl6/roast/commit/ab81dfbdd5

p6rt commented 9 years ago

From @usev6

I added two tests to S04-statements/for.t with commit https://github.com/perl6/roast/commit/ab81dfbdd5

p6rt commented 9 years ago

@usev6 - Status changed from 'new' to 'open'

p6rt commented 9 years ago

From @labster

This bug came up for discussion today​:

labster​: m​: say ("-AAAA-").map( { my $/; .subst(/(A+)/, { $0.chars } ) }); camelia​: rakudo-moar d0a84b​: OUTPUT«-4-␤» Ven​: labster​: my $/ ? labster​: Ven​: apparently manually declaring the match variable in that block makes it update $0 labster​: m​: say ("-AAAA-").map( { .subst(/(A+)/, { $0.chars } ) }); camelia​: rakudo-moar d0a84b​: OUTPUT«-0-␤» FROGGS​: labster​: I guess it is about how we access the caller's $/ in method subst FROGGS​: labster​: I think we might want to pass the correct $/ from Perl6​::Actions to method subst, instead of doing the opposite

Bug appears in .map, .for, and for loop, possibly others.

On Mon Dec 01 09​:00​:45 2014, raiph wrote​:

See also​:

​118705​: [BUG] s/// doesn't update $/ inside for loop

​123323​: $0 in substitution

p6rt commented 8 years ago

From @FROGGS

Patch​: https://github.com/rakudo/rakudo/commit/32d7b08334 Tests​: https://github.com/perl6/roast/commit/f665268fde

Closing ticket.

p6rt commented 8 years ago

From @FROGGS

Patch​: https://github.com/rakudo/rakudo/commit/32d7b08334 Tests​: https://github.com/perl6/roast/commit/f665268fde

Closing ticket.

p6rt commented 8 years ago

@FROGGS - Status changed from 'open' to 'resolved'