This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #108224] B::Deparse doesn't recognize for continue block
authorHojung Youn <amoc.yn@gmail.com>
Sun, 15 Jan 2012 03:03:19 +0000 (12:03 +0900)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 15 Jan 2012 06:36:42 +0000 (22:36 -0800)
B::Deparse foreach scoping problem was fixed at cf24a84005,
which was issued at #30504. But B::Deparse was blinded
temporarily by this commit so that it couldn't recognize
foreach continue block for a moment.

foreach statement generates 'nextstate', 'stub', 'leave', or
'scope' root opcode at will when foreach statement is not used
as a oneline statement modifier. So all the case of opcodes
should be checked.

Some tests for foreach scoping and continue block are attached.

related: #30504

dist/B-Deparse/Deparse.pm
dist/B-Deparse/t/deparse.t

index ec5295e..296be02 100644 (file)
@@ -2975,7 +2975,7 @@ sub loop_common {
            $var = "\$" . $self->deparse($var, 1);
        }
        $body = $kid->first->first->sibling; # skip OP_AND and OP_ITER
-       if (!is_state $body->first and $body->first->name ne "stub") {
+       if (!is_state $body->first and $body->first->name !~ /^(?:stub|leave|scope)$/) {
            confess unless $var eq '$_';
            $body = $body->first;
            return $self->deparse($body, 2) . " foreach ($ary)";
index 6ede945..2831981 100644 (file)
@@ -1080,3 +1080,47 @@ $_ = -(f());
 ####
 # require <binop>
 require 'a' . $1;
+####
+#[perl #30504] foreach-my postfix/prefix difference
+$_ = 'foo' foreach my ($foo1, $bar1, $baz1);
+foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
+foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
+>>>>
+$_ = 'foo' foreach (my($foo1, $bar1, $baz1));
+foreach $_ (my($foo2, $bar2, $baz2)) {
+    $_ = 'foo';
+}
+foreach my $i (my($foo3, $bar3, $baz3)) {
+    $i = 'foo';
+}
+####
+#[perl #108224] foreach with continue block
+foreach (1 .. 3) { print } continue { print "\n" }
+foreach (1 .. 3) { } continue { }
+foreach my $i (1 .. 3) { print $i } continue { print "\n" }
+foreach my $i (1 .. 3) { } continue { }
+>>>>
+foreach $_ (1 .. 3) {
+    print $_;
+}
+continue {
+    print "\n";
+}
+foreach $_ (1 .. 3) {
+    ();
+}
+continue {
+    ();
+}
+foreach my $i (1 .. 3) {
+    print $i;
+}
+continue {
+    print "\n";
+}
+foreach my $i (1 .. 3) {
+    ();
+}
+continue {
+    ();
+}