Skip to content
Permalink
Browse files

Fix handling of $_ in blocks to if/unless mods

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 c0f83788278a6e8d6bc0f25eb35f68d9448e30c5
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/Perl6/Actions.nqp
@@ -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);

0 comments on commit c0f8378

Please sign in to comment.
You can’t perform that action at this time.