diff --git a/Niecza/Actions.pm b/Niecza/Actions.pm index aec0a5ab..e949573c 100644 --- a/Niecza/Actions.pm +++ b/Niecza/Actions.pm @@ -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); diff --git a/test.pl b/test.pl index d8cfdf47..8025ed06 100644 --- a/test.pl +++ b/test.pl @@ -10,7 +10,7 @@ ($num) say ("1.." ~ $num); } -plan 18; +plan 19; ok 1, "one is true"; ok 2, "two is also true"; @@ -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";