ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: tom.enebo@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95155] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE.
Date: Mon, 30 Sep 2019 18:21:41 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-81795.20190930182140.c85244edb56aa4d1@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16181.20190925180551@ruby-lang.org

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/

  parent reply	other threads:[~2019-09-30 18:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-81795.20190930182140.c85244edb56aa4d1@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).