Skip to content

Commit

Permalink
[perl #115066] Fix wrongly nested ‘use’ deparsing
Browse files Browse the repository at this point in the history
B::Deparse was incorrectly putting ‘use’ statements and BEGIN blocks
inside other ‘use’ statements containing do-blocks, even if they were
originally outside.

Subroutines (except for cloned closures, which we don’t have to worry
about here) have an OUTSIDE pointer, pointing to the outer sub con-
taining the declaration of the sub in question.  So we can check that
to make sure we are putting the sub declaration in the right place.

Not only does this fix the reported case, but it also will allow
sequence numbers in inner subs to be reused by statements in outer
subs, which I may need in a future commit.
  • Loading branch information
Father Chrysostomos committed Nov 15, 2014
1 parent c62df97 commit d88d1fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/B/Deparse.pm
Expand Up @@ -1645,10 +1645,18 @@ sub seq_subs {
#push @text, "# ($seq)\n";

return "" if !defined $seq;
my @pending;
while (scalar(@{$self->{'subs_todo'}})
and $seq > $self->{'subs_todo'}[0][0]) {
my $cv = $self->{'subs_todo'}[0][1];
my $outside = $cv && $cv->OUTSIDE;
if ($cv and ${$cv->OUTSIDE || \0} != ${$self->{'curcv'}}) {
push @pending, shift @{$self->{'subs_todo'}};
next;
}
push @text, $self->next_todo;
}
unshift @{$self->{'subs_todo'}}, @pending;
return @text;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/B/Deparse.t
Expand Up @@ -367,12 +367,11 @@ EOCODJ
}

# [perl #115066]
$::TODO = ' ';
my $prog = 'use constant FOO => do { 1 }; no overloading; die';
$a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
use constant ('FOO', do {
1;
1
});
no overloading;
die;
Expand Down

0 comments on commit d88d1fe

Please sign in to comment.