Skip Menu |
Report information
Id: 131152
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: usikov [at] ziex.by
Cc:
AdminCc:

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



Date: Fri, 14 Apr 2017 20:35:58 +0300
To: rakudobug [...] perl.org
From: Александр Усиков <usikov [...] ziex.by>
Subject: [BUG](FIRST/LAST Phasers doesn't work in loop/while structures)
Download (untitled) / with headers
text/plain 1.5k
perl6 -v
This is Rakudo version 2017.01 built on MoarVM version 2017.01

sub f {
   my $i = 0;
   while True {
      FIRST { say "FIRST: $i"};
      LAST { say "LAST: $i"};
      last if ++$i > 100;
   }
}

doesn't compile: 
===SORRY!===
Cannot reference undeclared local 'LOOP_BLOCK_1'

--------------------------
without FIRST gives an error:

sub f {
   my $i = 0;
   while True {
      # FIRST { say "FIRST: $i"};
      LAST { say "LAST: $i"};
      last if ++$i > 100;
   }
}

f();

LAST: 0
No such method '!capture_phasers' for invocant of type 'Code'
  in block <unit> at t1.p6 line 16

----------------------------
in Promises compiles but gives random results:

await do for 1..10 { start {
   my $i = 0;
   loop {
      FIRST { say "FIRST: $i"};
      LAST { say "LAST: $i"};
      last if ++$i > 100;
   }
} }


FIRST: 0
FIRST: 0
FIRST: 2
FIRST: 0
LAST: 0
LAST: 5
LAST: 5
FIRST: 0
FIRST: 0
FIRST: 64
LAST: 103
LAST: 103
LAST: 103
FIRST: 103
LAST: 104
FIRST: 2
FIRST: 98
LAST: 102
LAST: 102
LAST: 102

---------------------------------
changing loop/while to for 1..* solves first two issues, but:

-----------------------------------
using for 1..* instead of loop give more stable, but still sometimes incorrect results with promises:

await do for 1..10 { start {
   my $i = 0;
   for 1..* {
      FIRST { say "FIRST: $i"};
      LAST { say "LAST: $i"};
      #say $i;
      last if ++$i > 100;
   }
} }


FIRST: 0
FIRST: 0
FIRST: 77
FIRST: 0
LAST: 101
LAST: 101
LAST: 101
LAST: 101
FIRST: 0
FIRST: 0
LAST: 101
FIRST: 0
LAST: 101
FIRST: 0
LAST: 101
FIRST: 0
LAST: 101
FIRST: 0
LAST: 101
LAST: 101




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