# New Ticket Created by  Александр Усиков 
# Please include the string:  [perl #131152]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=131152 >


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

Reply via email to