Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

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

Closed p6rt closed 7 years ago

p6rt commented 10 years ago

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

Searchable as RT122504$

p6rt commented 10 years ago

From @masak

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

p6rt commented 10 years ago

From @pmichaud

Per further discussion on #perl6...

By definition, I think that "lexotic" sharply limits what can be done statically. If a C\ (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 commented 10 years ago

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

p6rt commented 10 years ago

From @lizmat

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

p6rt commented 7 years ago

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 \ at -e line 1

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

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

Bisectable points to this fix from Dec 2015​:

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

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

p6rt commented 7 years ago

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 \ at -e line 1

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

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

Bisectable points to this fix from Dec 2015​:

https://gist.github.com/Whateverable/63b5da597e229d167d8708a43d4501de https://github.com/rakudo/rakudo/commit/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 commented 7 years ago

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 commented 7 years ago

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