Issue #13844 has been updated by headius (Charles Nutter).


Oh also...IRB is a very weird beast. The code you enter isn't really running at toplevel; it's running in an eval that's likely within a block or method scope (I haven't looked recently). As a result, things you'd expect to work at toplevel (like returns, now) don't behave the same way. This bug is only about returns at the true top level scope in a Ruby file or -e script.

----------------------------------------
Bug #13844: Toplevel returns should fire ensures
https://bugs.ruby-lang.org/issues/13844#change-66326

* Author: headius (Charles Nutter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
In the following contexts, a return always fires the ensure that wraps it:

```
[] ~/projects/ruby $ ruby -e 'def foo; return; ensure; p :x; end; foo'
:x

[] ~/projects/ruby $ ruby -e 'def foo; 1.times { begin; return; ensure; p :x; end }; end; foo'
:x
```

However the new 2.4 support for toplevel returns does *not* fire ensures:

```
$ ruby -e 'begin; return; ensure; p :x; end'
<no output>
```

I believe this is inconsistent with how returns work everywhere else (both valid and invalid returns always fire ensure) and it should be changed to match.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>