Skip to content

Commit

Permalink
Fix pre-init blocks in non-void context
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan O'Rear committed Jul 14, 2010
1 parent 8afac05 commit ece8139
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions Niecza/Actions.pm
Expand Up @@ -1222,6 +1222,7 @@ sub statement_prefix {}
sub statement_prefix__S_PREMinusINIT { my ($cl, $M) = @_;
my $var = $cl->gensym;

$::CURLEX->{'!slots'}{$var} = 1;
push @{ $::CURLEX->{'!decls'} //= [] },
Decl::PreInit->new(var => $var, code => $M->{blast}{_ast}, shared => 1);

Expand Down
14 changes: 9 additions & 5 deletions test.pl
Expand Up @@ -10,7 +10,7 @@ ($num)
say ("1.." ~ $num);
}

plan 18;
plan 19;

ok 1, "one is true";
ok 2, "two is also true";
Expand Down Expand Up @@ -71,8 +71,12 @@ ($num)
ok $a == 55, "looping works";
}

my $x;
PRE-INIT {
$x = 1;
{
my $x;
PRE-INIT {
$x = 1;
}
ok $x, "changes made in the protolexpad are visible at runtime";
}
ok $x, "changes made in the protolexpad are visible at runtime";

ok PRE-INIT { 1 }, "preinit blocks can return values";

0 comments on commit ece8139

Please sign in to comment.