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' invoked outside of a routine should throw an exception #3480

Closed
p6rt opened this issue Aug 11, 2014 · 8 comments
Closed

'return' invoked outside of a routine should throw an exception #3480

p6rt opened this issue Aug 11, 2014 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Aug 11, 2014

Migrated from rt.perl.org#122504 (status was 'resolved')

Searchable as RT122504$

@p6rt
Copy link
Author

p6rt commented Aug 11, 2014

From @masak

<moritz> m​: -> $f, $s { return $f + $s }(23, 42)
<camelia> rakudo-moar 11afe1​: ( no output )
<moritz> m​: say -> $f, $s { return $f + $s }(23, 42)
<camelia> rakudo-moar 11afe1​: ( no output )
<moritz> m​: say (-> $f, $s { return $f + $s })(23, 42)
<camelia> rakudo-moar 11afe1​: ( no output )
<moritz> ffs?
<moritz> m​: say 23 + 42
<camelia> rakudo-moar 11afe1​: OUTPUT«65␤»
<FROGGS> m​: say( -> $f, $s { return $f + $s }(23, 42) )
<camelia> rakudo-moar 11afe1​: ( no output )
<FROGGS> err
<moritz> oh
<FROGGS> a return in a pointy >.<
<moritz> return inside a lambda is a BAD IDEA
<moritz> return is only for routines
<moritz> it should say "return without a routine"
<FROGGS> if it does not do that it should state that the
return-exception missed its handler
<masak> m​: return; say "alive"
<camelia> rakudo-moar 11afe1​: ( no output )
<masak> I'd go so far as to consider that a bug.
<FROGGS> yeah
<masak> it can be caught *statically*.
<PerlJam> agreed
* masak submits rakuobug
<moritz> since control exceptions are lexotic, and all that
<masak> `return` in the mainline is always wrong.
<PerlJam> masak​: sub MAIN { return 42; } # ;-)
<masak> PerlJam​: that's un-wrong but meaningless :)
<PerlJam> masak​: it's a gentle nudge toward improving the precision of
our words :)
<masak> PerlJam​: I stand by what I said. MAIN is a sub, so `return` is
fine there.
<masak> PerlJam​: it's only not fine outside of any routine.
<FROGGS> "Can only return from within a method or sub"
<masak> FROGGS​: "routine"
<masak> that's the Perl 6 word for it.
<masak> FROGGS​: you can return from a macro, too. for example.

@p6rt
Copy link
Author

p6rt commented Aug 11, 2014

From @pmichaud

Per further discussion on #perl6...

By definition, I think that "lexotic" sharply limits what can be done statically. If a C<return> (inside of a block) isn't lexically scoped, it's dynamically scoped. About the only place it could be caught statically is as a bare 'return' inside of a mainline (and even there, I'm wondering if there is a case where a mainline might dynamically be invoked from inside of a Routine).

However, a return that is invoked dynamically outside of any Routine should throw a runtime error, so I'm changing the topic of this ticket to match that.

Pm

@p6rt
Copy link
Author

p6rt commented Aug 11, 2014

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

@p6rt
Copy link
Author

p6rt commented Aug 31, 2014

From @lizmat

[14​:22​:01] <lizmat> m​: my $a = do { return 42 }
[14​:22​:02] <+camelia> rakudo-moar 5f9cd5​: ( no output )
[14​:22​:34] <lizmat> $ MVM_SPESH_DISABLE=1 perl6 -e 'my $a = do { return 42 }'
[14​:22​:34] <lizmat> Segmentation fault​: 11
[14​:22​:41] <lizmat> segfaults locally for me
[14​:22​:54] <lizmat> can someone confirm ?
[14​:23​:29] <colomon> seems to throw me in the REPL?!?
[14​:23​:41] <colomon> lizmat​: ^^
[14​:23​:57] <colomon> ah, no, I see
[14​:24​:04] <colomon> seg fault on OS X
[14​:24​:14] <colomon> and linux
[14​:24​:27] <lizmat> also in the REPL
[14​:25​:25] <colomon> lizmat​: wasn't actually the REPL, I missed the closing quote in my copy-n-paste so the shell wanted more input.
[14​:25​:51] <lizmat> actually, I can golf it down to just { return }
[14​:26​:01] <lizmat> $ MVM_SPESH_DISABLE=1 perl6 -e '{ return }'
[14​:26​:01] <lizmat> Segmentation fault​: 11
[14​:26​:24] <lizmat> hmmm... actually just return is enough
[14​:27​:04] lizmat rakudobugs
[14​:27​:18] <colomon> lizmat​: confirmed for just { return }, too
[14​:27​:32] <lizmat> $ perl6-p -e 'return'
[14​:27​:32] <lizmat> Attempt to return outside of any Routine
[14​:27​:39] <lizmat> is what it probably should be

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @smls

A `return` outside a routine now always seems to throw a run-time error, as it should​:

  $ perl6 -e 'return'
  Attempt to return outside of any Routine
  in block <unit> at -e line 1

  $ perl6 -e '{ return }'
  Attempt to return outside of any Routine
  in block <unit> at -e line 1

  $ MVM_SPESH_DISABLE=1 perl6 -e '{ return }'
  Attempt to return outside of any Routine
  in block <unit> at -e line 1

Bisectable points to this fix from Dec 2015​:

  https://gist.github.com/Whateverable/63b5da597e229d167d8708a43d4501de
  rakudo/rakudo@a4ca12a

This ticket can be closed once tests are added to roast.

@p6rt
Copy link
Author

p6rt commented Sep 13, 2017

From @skids

On Sun, 10 Sep 2017 11​:22​:29 -0700, smls75@​gmail.com wrote​:

A `return` outside a routine now always seems to throw a run-time
error, as it should​:

$ perl6 -e 'return'
Attempt to return outside of any Routine
in block <unit> at -e line 1

$ perl6 -e '{ return }'
Attempt to return outside of any Routine
in block <unit> at -e line 1

$ MVM_SPESH_DISABLE=1 perl6 -e '{ return }'
Attempt to return outside of any Routine
in block <unit> at -e line 1

Bisectable points to this fix from Dec 2015​:

https://gist.github.com/Whateverable/63b5da597e229d167d8708a43d4501de
rakudo/rakudo@a4ca12a

This ticket can be closed once tests are added to roast.

It looks to me like the tests already in S04-statements/return.t should suffice, no?

(This appears to be another case where a bug filed and fixed during the
craziness of the 2015 release and GLR was not followed up in RT
by closing the ticket.)

Since MVM_* environment variables are not part of the Perl 6 specification,
tests for those cases aren't a matter for roast... possibly they could
go in the rakudo tree, but it would probably be better to figure out how to golf
that SEGV down into an nqp one-liner... rakudo can no longer produce the
situation that caused that SEGV, so... where to follow that thread I dunno.

@p6rt
Copy link
Author

p6rt commented Sep 16, 2017

From @smls

It looks to me like the tests already in S04-statements/return.t
should suffice, no?

You're right. Closing the ticket.

@p6rt
Copy link
Author

p6rt commented Sep 16, 2017

@smls - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 16, 2017
@p6rt p6rt added the testneeded label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant