Subject: | [BUG] Binding to `state` variable silently fails |
$ perl6 -v
This is Rakudo version 2017.03-20-g027aa54 built on MoarVM version 2017.03-7-g029d121
implementing Perl 6.c.
$ perl6 -e 'state $x = 42; dd $x'
Int $x = 42
$ perl6 -e 'state $x := 42; dd $x'
Mu
I also have a small snippet where the `state` declaration uses assignment, but later
in the code a binding is used for the same variable. The result of the routine changes,
based on whether it's a binding or an assignment (also, I believe the result with binding
is incorrect:
use MONKEY;
sub z {
my @found;
for $^v.pairs {
my $value := .value;
state $max = $value;
my $cmp;
nqp::if(
nqp::iseq_i( ($cmp := $value cmp $max), 1 ),
### CHANGING FROM $max := to $max = BELOW CHANGES RESULT
nqp::stmts((@found = $_), ($max := $value)),
nqp::if(
nqp::iseq_i($cmp, 0),
@found.push: $_
)
)
}
@found.List
}
dd z (1, 2, 65, -6, 4);