From: Stephen McCamant <smcc@mit.edu>
Date: Mon, 28 Jun 2004 18:26:24 +0000 (-0700)
Subject: Re: [perl #30504] B::Deparse scoping problem with for loop
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cf24a84005bbe3e9a7eec3a0b9eb2e5e5b89c450;p=p5sagit%2Fp5-mst-13.2.git

Re: [perl #30504] B::Deparse scoping problem with for loop
Message-ID: <16608.50496.787002.560481@apocalypse.OCF.Berkeley.EDU>

p4raw-id: //depot/perl@23046
---

diff --git a/ext/B/B/Deparse.pm b/ext/B/B/Deparse.pm
index 73075cd..adda35f 100644
--- a/ext/B/B/Deparse.pm
+++ b/ext/B/B/Deparse.pm
@@ -1013,6 +1013,8 @@ sub maybe_local {
 	and not $self->{'avoid_local'}{$$op}) {
 	my $our_local = ($op->private & OPpLVAL_INTRO) ? "local" : "our";
 	if( $our_local eq 'our' ) {
+	    # XXX This assertion fails code with non-ASCII identifiers,
+	    # like ./ext/Encode/t/jperl.t
 	    die "Unexpected our($text)\n" unless $text =~ /^\W(\w+::)*\w+\z/;
 	    $text =~ s/(\w+::)+//;
 	}
@@ -2514,8 +2516,13 @@ sub loop_common {
 	} elsif ($var->name eq "gv") {
 	    $var = "\$" . $self->deparse($var, 1);
 	}
-	$head = "foreach $var ($ary) ";
 	$body = $kid->first->first->sibling; # skip OP_AND and OP_ITER
+	if (!is_state $body->first and $body->first->name ne "stub") {
+	    confess unless $var eq '$_';
+	    $body = $body->first;
+	    return $self->deparse($body, 2) . " foreach ($ary)";
+	}
+	$head = "foreach $var ($ary) ";
     } elsif ($kid->name eq "null") { # while/until
 	$kid = $kid->first;
 	my $name = {"and" => "while", "or" => "until"}->{$kid->name};