Skip to content

Commit

Permalink
Fix handling of $_ in blocks to if/unless mods
Browse files Browse the repository at this point in the history
The program:

    for 1..3 { { say $_; last } if $_ == 2 }

Recently started to output `True` instead of `2`. This bissected to the
recent optimizer change to the immediate block inlining. However, even
disabling the optimizer still showed up the bug. In fact, a bissect with
the optimizer disabled revealed that the optimizer had a bug, fixed in
commit 541a4f1, that caused it to do immediate inlining of blocks that
it shouldn't have before. This optimizer bug hid another bug; a bissect
with the optimizer disabled led to a fix from around a year ago, which
in turn caused `{ say $_ } if $_ == 2` to be compiled as if it were
`if $_ == 2 -> $_ { say $_ }`.

This change makes sure that we compile the construct correctly, thus
fixing the issue that the optimizer bug had hidden.
  • Loading branch information
jnthn committed Jan 15, 2019
1 parent 6a8f08b commit c0f8378
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Perl6/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,10 @@ class Perl6::Actions is HLL::Actions does STDActions {
my $cond_block := $past.ann('past_block');
remove_block($*W.cur_lexpad(), $cond_block);
$cond_block.blocktype('immediate');
unless $cond_block.ann('placeholder_sig') {
$cond_block.arity(0);
$cond_block.annotate('count', 0);
}
$past := $cond_block;
}
$mc_ast.push($past);
Expand Down

0 comments on commit c0f8378

Please sign in to comment.