[ruby-core:95156] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.

From: merch-redmine@...
Date: 2019-09-30 18:32:59 UTC
List: ruby-core #95156
Issue #16181 has been updated by jeremyevans0 (Jeremy Evans).


enebo (Thomas Enebo) wrote:
> Jeremy,  since you are only person who has looked would you say semantically this should be some error vs silently only executing part of a file?

I believe if `return` directly inside `class`/`module` is an error, `return` inside `proc` inside `class`/`module` should also be an error.  Since it cannot be a compile time error, it should be a runtime error (`LocalJumpError`).

Alternatively, we start to allow `return` inside `class`/`module`, and then the current behavior for `return` inside `proc` inside `class`/`module` makes sense.

----------------------------------------
Bug #16181: return from a proc in a module/class body returns out of script.  Should be LJE.
https://bugs.ruby-lang.org/issues/16181#change-81796

* Author: enebo (Thomas Enebo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
return is not allowed from class/module body.  But if we insert a return into a block then we can invoke the block then it returns all the way out of the script.  This has to be accidental behavior doesn't it?  I believe the case below should end up as a LocalJumpError:


```
class Foo
  proc { return }.call
end
puts "NEVER SEEN"
```

This behavior started some time in 2.5 (it used to be an LJE).



-- 
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>

In This Thread

Prev Next