From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 25E971F463 for ; Mon, 30 Sep 2019 18:21:53 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6FD68120972; Tue, 1 Oct 2019 03:21:42 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 74A66120933 for ; Tue, 1 Oct 2019 03:21:39 +0900 (JST) Received: by filter0082p3las1.sendgrid.net with SMTP id filter0082p3las1-23055-5D9247B5-D 2019-09-30 18:21:41.169913436 +0000 UTC m=+603042.785965703 Received: from herokuapp.com (unknown [18.232.111.68]) by ismtpd0073p1iad2.sendgrid.net (SG) with ESMTP id dvXHqZ3rQqSA_HKLozNM8A for ; Mon, 30 Sep 2019 18:21:41.144 +0000 (UTC) Date: Mon, 30 Sep 2019 18:21:41 +0000 (UTC) From: tom.enebo@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70710 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16181 X-Redmine-Issue-Author: enebo X-Redmine-Sender: enebo X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?CEgjm=2FKgaDwZgtms5cDYrJb3X=2F7GsuVdUT8RQZ9PoP1WHN+SzS30lx7=2F9hZFMv?= =?us-ascii?Q?ABjl7c6pGbwzGqbv3J4q8uCnGyzuEgrT8SQUPD8?= =?us-ascii?Q?hpR=2FWVkyQxCG8BfHU5qwQ=2FID7u8=2FrjdAUIgP1AH?= =?us-ascii?Q?gsUYKveZy3dfEtZGMA1YFJ0fwaDj3A9E0i9hqCo?= =?us-ascii?Q?KymK2O=2FI9hOsz4OznaGRURtmEMN0ZYrIfQQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95155 Subject: [ruby-core:95155] [Ruby master Bug#16181] return from a proc in a module/class body returns out of script. Should be LJE. X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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/