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

Toplevel return behavior (2.4) #4761

Closed
headius opened this issue Aug 28, 2017 · 3 comments
Closed

Toplevel return behavior (2.4) #4761

headius opened this issue Aug 28, 2017 · 3 comments
Labels
Milestone

Comments

@headius
Copy link
Member

@headius headius commented Aug 28, 2017

This issue tracks unimplemented top-level return behavior added in Ruby 2.4.

In MRI this feature was tracked in https://bugs.ruby-lang.org/issues/4840

The relevant tests, from test/mri/ruby/test_syntax.rb:test_return_toplevel, are copied here:

return; raise
begin return; rescue SystemExit; exit false; end
begin return; ensure exit false; end
begin ensure return; end
begin raise; ensure; return; end
begin raise; rescue; return; end
return false; raise
return 1; raise

Each of these lines in a -e should exit the process cleanly. The rescue-based cases expect the return to immediately exit the script body without firing ensures or rescues (more in this later). The remaining cases just check that the return does not execute any more lines in the script.

JRuby never implemented a top-level error when a return occurs outside of a method or block at toplevel, so some of these pass already. However the cases that check for ensures not running fail, since we implement those to the letter of the law in JRuby by using Java try/finally logic.

I am going to open an issue with MRI to clarify whether ensures should fire or not. I believe they should, since they do in all other contexts.

@headius
Copy link
Member Author

@headius headius commented Aug 28, 2017

@headius
Copy link
Member Author

@headius headius commented Aug 28, 2017

Link to #4293, #4687.

@headius
Copy link
Member Author

@headius headius commented Sep 5, 2017

ruby-core has modified toplevel return to fire ensures, matching our behavior. I will confirm with latest MRI tests.

@headius headius closed this Sep 5, 2017
@headius headius added this to the JRuby 9.2.0.0 milestone Sep 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.