Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return in block does not return from sub that is parameterised with that block #5895

Closed
p6rt opened this issue Dec 18, 2016 · 5 comments
Closed
Labels
regression Issue did not exist previously

Comments

@p6rt
Copy link

p6rt commented Dec 18, 2016

Migrated from rt.perl.org#130371 (status was 'rejected')

Searchable as RT130371$

@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

From @gfldex

my &block = { say 'returning from &block'; return };
sub returned-from(&code) { say 'enter returned-from'; code; say 'leave returned-from' };
sub forcing-a-return { returned-from &block };
forcing-a-return;

# OUTPUT«enter returned-from␤returning from &block␤Attempt to return outside of any Routine␤ in block <unit> at <tmp> line 1␤␤»
# expected
# OUTPUT«enter returned-from␤returning from &block␤»
# this may be a regression caused by a4ca12afa30be4ce5dfc3602f54a5563d069ffa5

@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

From @moritz

Hi,

On 18.12.2016 15​:35, Wenzel Peppmeyer (via RT) wrote​:

# New Ticket Created by Wenzel Peppmeyer
# Please include the string​: [perl #​130371]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130371 >

my &block = { say 'returning from &block'; return };
sub returned-from(&code) { say 'enter returned-from'; code; say 'leave returned-from' };
sub forcing-a-return { returned-from &block };
forcing-a-return;

# OUTPUT«enter returned-from␤returning from &block␤Attempt to return outside of any Routine␤ in block <unit> at <tmp> line 1␤␤»
# expected
# OUTPUT«enter returned-from␤returning from &block␤»
# this may be a regression caused by a4ca12afa30be4ce5dfc3602f54a5563d069ffa5

I'm pretty sure that's not a bug; &return is supposed to be tied to the
lexically outer Routine, and in this example, there is no lexically
outer Routine, so the error message is valid.

Cheers,
Moritz

--
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/

@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

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

@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

@moritz - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Dec 18, 2016
@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

From @zoffixznet

On Sun, 18 Dec 2016 08​:44​:31 -0800, moritz wrote​:

Hi,

On 18.12.2016 15​:35, Wenzel Peppmeyer (via RT) wrote​:

# New Ticket Created by Wenzel Peppmeyer
# Please include the string​: [perl #​130371]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130371 >

my &block = { say 'returning from &block'; return };
sub returned-from(&code) { say 'enter returned-from'; code; say
'leave returned-from' };
sub forcing-a-return { returned-from &block };
forcing-a-return;

# OUTPUT«enter returned-from␤returning from &block␤Attempt to return
outside of any Routine␤ in block <unit> at <tmp> line 1␤␤»
# expected
# OUTPUT«enter returned-from␤returning from &block␤»
# this may be a regression caused by
a4ca12afa30be4ce5dfc3602f54a5563d069ffa5

I'm pretty sure that's not a bug; &return is supposed to be tied to
the
lexically outer Routine, and in this example, there is no lexically
outer Routine, so the error message is valid.

Cheers,
Moritz

Isn't this just throwing a CX​::Return control exception and thus should work? How/when does the tying to the lexically outer Routine happen?

Such method works for other control exceptions, like, CX​::Last​:

my &block = { say 'returning from &block'; last };
sub last-from(&code) { say 'enter returned-from'; code; say 'leave returned-from' };
for ^6 {
  .say;
  last-from █
}

# OUTPUT​:
# 0
# enter returned-from
# returning from &block

@p6rt p6rt added the regression Issue did not exist previously label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Issue did not exist previously
Projects
None yet
Development

No branches or pull requests

1 participant