Actions
Bug #19779
closed`eval "return"` at top level raises `LocalJumpError`
Bug #19779:
`eval "return"` at top level raises `LocalJumpError`
Actions
Added by andrykonchin (Andrew Konchin) almost 3 years ago. Updated over 2 years ago.
Since we allow top-level return (from 2.4), it is nice to allow this too. But to be frank, it is low priority.
Matz.
I submitted a pull request to fix this: https://github.com/ruby/ruby/pull/8766
@jeremyevans0 (Jeremy Evans) Matz said go ahead in today's dev meeting.
Applied in changeset git|3a88de3ca73052809f5c0bfb4ef8cd435b29ae5f.
Support eval "return" at toplevel
Since Ruby 2.4, return is supported at toplevel. This makes eval "return"
also supported at toplevel.
This mostly uses the same tests as direct return at toplevel, with a couple
differences:
END {return if false} is a SyntaxError, but END {eval "return" if false}
is not an error since the eval is never executed. END {return} is a
SyntaxError, but END {eval "return"} is a LocalJumpError.
The following is a SyntaxError:
However, the following is not, because the eval is never executed:
Fixes [Bug #19779]