Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Binding to `state` variable silently fails #6162

Open p6rt opened 7 years ago

p6rt commented 7 years ago

Migrated from rt.perl.org#131043 (status was 'open')

Searchable as RT131043$

p6rt commented 7 years ago

From @zoffixznet

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

p6rt commented 7 years ago

From @geekosaur

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​:

# 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-archive.perl.org/perl6/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 @&#8203;found;
    for $^v\.pairs \{
        my $value  := \.value;
        state $max = $value;
        my $cmp;
        nqp&#8203;::if\(
            nqp&#8203;::iseq\_i\( \($cmp := $value cmp $max\), 1 \),

            \#\#\# CHANGING FROM $max := to $max = BELOW CHANGES RESULT
            nqp&#8203;::stmts\(\(@&#8203;found = $\_\), \($max := $value\)\),
            nqp&#8203;::if\(
                nqp&#8203;::iseq\_i\($cmp, 0\),
                @&#8203;found\.push&#8203;: $\_
            \)
        \)
    \}
    @&#8203;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

p6rt commented 7 years ago

The RT System itself - Status changed from 'new' to 'open'