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

Owner: Nobody
Requestors: cpan [at] zoffix.com
Cc:
AdminCc:

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



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);
Date: Wed, 22 Mar 2017 13:53:17 -0400
CC: bugs-bitbucket [...] rt.perl.org
From: Brandon Allbery <allbery.b [...] gmail.com>
Subject: Re: [perl #131043] [BUG] Binding to `state` variable silently fails
To: perl6-compiler <perl6-compiler [...] perl.org>
Download (untitled) / with headers
text/plain 1.7k
I can't help but think that binding a state variable should be illegal, and doing so will have unexpected effects.

On Wed, Mar 22, 2017 at 1:48 PM, Zoffix Znet <perl6-bugs-followup@perl.org> wrote:
Show quoted text
# New Ticket Created by  Zoffix Znet
# Please include the string:  [perl #131043]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=131043 >


    $ 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);



--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net


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