Skip Menu |
Report information
Id: 127422
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: ugexe [at] cpan.org
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: Behavior of state vars in variations of `do while` inconsistent
Download (untitled) / with headers
text/plain 433b
The following prints an incrementing count (expected): `my $x = do { while ( 1 ) { state $a++; say $a; }; }; say $x;` `do while ( 1 ) { state $a++; say $a; }; say $x;` The following only prints `1`s (expected incrementing count): `my $x = do while ( 1 ) state $a++; say $a; }; }; say $x;` When `do` does not use braces it works as expected unless its also used in assignment. When `do` does use braces it always works as expected.
Download (untitled) / with headers
text/plain 148b
As another data point, the problem persists also when using parens instead of "do" to enforce return values: (loop { state $a++; say $a; })[^5]
See also #117975 which might be related.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org