ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95090] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
@ 2019-09-25 18:05 ` tom.enebo
  2019-09-27 23:00 ` [ruby-core:95138] " merch-redmine
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: tom.enebo @ 2019-09-25 18:05 UTC (permalink / raw)
  To: ruby-core

Issue #16181 has been reported by enebo (Thomas Enebo).

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95138] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
  2019-09-25 18:05 ` [ruby-core:95090] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE tom.enebo
@ 2019-09-27 23:00 ` merch-redmine
  2019-09-30 18:21 ` [ruby-core:95155] " tom.enebo
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: merch-redmine @ 2019-09-27 23:00 UTC (permalink / raw)
  To: ruby-core

Issue #16181 has been updated by jeremyevans0 (Jeremy Evans).


It looked into this behavior, which started in Ruby 2.4 (when top level return started being allowed).

`return` not being allowed directly in class/module body is a parse error, because the parser knows that it cannot be valid.  However, you cannot have the behavior inside of a block inside of class/module be a parse error, because you do not know how the block will be evaluated:

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

Similarly, though this operates as a top level return, the warning for top level return with argument does not take effect, because the compiler doesn't know it will operate as a top level return:

```ruby
class Foo
  proc { return 1 }.call # no top level return with argument warning
end
puts "NEVER SEEN"
```

I don't think the compiler has enough information to handle this correctly, because it doesn't know at compilation time whether the block will be executed as a proc or as a lambda.

I do agree that a LocalJumpError is the most appropriate way to handle this.

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95155] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
  2019-09-25 18:05 ` [ruby-core:95090] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE tom.enebo
  2019-09-27 23:00 ` [ruby-core:95138] " merch-redmine
@ 2019-09-30 18:21 ` tom.enebo
  2019-09-30 18:32 ` [ruby-core:95156] " merch-redmine
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: tom.enebo @ 2019-09-30 18:21 UTC (permalink / raw)
  To: ruby-core

Issue #16181 has been updated by enebo (Thomas Enebo).


I agree this is impossible to be done by parser or at iseq generation time.   It must be done when return is invoked.

JRuby will return LocalJumpError for this for 9.2.9.0.  It also had from 9.2.6.0 and earlier.

As a runtime LJE we know lexically it is defined within a module/class and we can also look up stack to see if it has migrated or not (I assume MRI has even more flexibility in this than JRuby does). Similarly we know it is a lambda or not at that point so that is not really a problem at runtime.

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?

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95156] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-09-30 18:21 ` [ruby-core:95155] " tom.enebo
@ 2019-09-30 18:32 ` merch-redmine
  2019-09-30 20:11 ` [ruby-core:95159] " tom.enebo
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: merch-redmine @ 2019-09-30 18:32 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95159] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-09-30 18:32 ` [ruby-core:95156] " merch-redmine
@ 2019-09-30 20:11 ` tom.enebo
  2019-09-30 23:13 ` [ruby-core:95162] " merch-redmine
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: tom.enebo @ 2019-09-30 20:11 UTC (permalink / raw)
  To: ruby-core

Issue #16181 has been updated by enebo (Thomas Enebo).


Ok cool.  Let's hope we get some more consensus on this.  I don't like deviating from MRI in behavior so I hope to see more come to the same conclusion.

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95162] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-09-30 20:11 ` [ruby-core:95159] " tom.enebo
@ 2019-09-30 23:13 ` merch-redmine
  2019-10-01 15:03 ` [ruby-core:95174] " tom.enebo
  2019-10-02 15:14 ` [ruby-core:95190] " merch-redmine
  7 siblings, 0 replies; 8+ messages in thread
From: merch-redmine @ 2019-09-30 23:13 UTC (permalink / raw)
  To: ruby-core

Issue #16181 has been updated by jeremyevans0 (Jeremy Evans).


I've added a pull request that makes `return` in `proc` in `class`/`module` a `LocalJumpError`: https://github.com/ruby/ruby/pull/2511

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95174] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2019-09-30 23:13 ` [ruby-core:95162] " merch-redmine
@ 2019-10-01 15:03 ` tom.enebo
  2019-10-02 15:14 ` [ruby-core:95190] " merch-redmine
  7 siblings, 0 replies; 8+ messages in thread
From: tom.enebo @ 2019-10-01 15:03 UTC (permalink / raw)
  To: ruby-core

Issue #16181 has been updated by enebo (Thomas Enebo).


I added a comment about removing the pre 2.7 spec as it is unintended behavior.

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95190] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
       [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2019-10-01 15:03 ` [ruby-core:95174] " tom.enebo
@ 2019-10-02 15:14 ` merch-redmine
  7 siblings, 0 replies; 8+ messages in thread
From: merch-redmine @ 2019-10-02 15:14 UTC (permalink / raw)
  To: ruby-core

Issue #16181 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

Fixed by commit:ef697388becedf36966a2edcdcf88baca342b9e2.

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

* Author: enebo (Thomas Enebo)
* Status: Closed
* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-10-02 15:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16181.20190925180551@ruby-lang.org>
2019-09-25 18:05 ` [ruby-core:95090] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE tom.enebo
2019-09-27 23:00 ` [ruby-core:95138] " merch-redmine
2019-09-30 18:21 ` [ruby-core:95155] " tom.enebo
2019-09-30 18:32 ` [ruby-core:95156] " merch-redmine
2019-09-30 20:11 ` [ruby-core:95159] " tom.enebo
2019-09-30 23:13 ` [ruby-core:95162] " merch-redmine
2019-10-01 15:03 ` [ruby-core:95174] " tom.enebo
2019-10-02 15:14 ` [ruby-core:95190] " merch-redmine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).