# New Ticket Created by "Carl Mäsak"
# Please include the string: [perl #123732]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=123732 >
<masak> m: for ^5 { .say; NEXT { return } }
<camelia> rakudo-moar 613c0b: OUTPUT«01234»
<masak> that last one, besides wrongly compiling (IMO), did not have
the wrong runtime semantics I expected it to.
<masak> m: say "A"; return; say "B"
<camelia> rakudo-moar 613c0b: OUTPUT«A»
<masak> m: for ^5 { say "A"; return; say "B" }
<camelia> rakudo-moar 613c0b: OUTPUT«A»
<masak> ok, `return` should not bind to `NEXT` phasers
<masak> m: for ^5 { .say; NEXT { say "A" }; NEXT { return } }
<camelia> rakudo-moar 613c0b: OUTPUT«01234»
<masak> seems it's worse than that: `return` in a `NEXT` binds to the iteration.
* masak submits rakudobug for `return` in a `NEXT` working at all
outside of a routine
<masak> m: sub foo { for ^3 { NEXT { return $_ } }; return 42 }; say foo
<camelia> rakudo-moar 613c0b: OUTPUT«0»
<masak> ...but *inside* a routine it seems to do the right thing. weird.
Point of order. We have a separate ticket (RT #122504) for `return`
dynamically outside of a routine; this ticket is not about that.
This ticket is about `return` having some unexpected/unwanted behavior
inside of a `NEXT` in a loop outside of a routine. Even here, it
should fail (preferably statically, at the very least dynamically).
The current (wrong) behavior of `return` outside of a routine is to
exit the program. *This* `return` inside a `NEXT` exits the iteration.
Ideally, the resolution of #122504 will also fix this ticket.
Reporting this just in case, because the wrong behavior is different.