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=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham 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 242FA1F463 for ; Fri, 27 Sep 2019 23:00:54 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 88105120ACC; Sat, 28 Sep 2019 08:00:40 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id DD7B6120A19 for ; Sat, 28 Sep 2019 08:00:37 +0900 (JST) Received: by filter0144p3mdw1.sendgrid.net with SMTP id filter0144p3mdw1-23168-5D8E9492-B5 2019-09-27 23:00:34.867509712 +0000 UTC m=+354814.207892080 Received: from herokuapp.com (unknown [54.167.110.97]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id aey3ABqNS-S7h2NCne_-Bw for ; Fri, 27 Sep 2019 23:00:35.002 +0000 (UTC) Date: Fri, 27 Sep 2019 23:00:35 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70693 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16181 X-Redmine-Issue-Author: enebo X-Redmine-Sender: jeremyevans0 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?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BIQiwEfzQDgKVAz3ZAGnSFC7GycHsE8FtXmoAmb?= =?us-ascii?Q?tUn0pyfdspvJ=2Fj0is3i+S6LoGwtCx+7WE=2FgX+3A?= =?us-ascii?Q?6Jcc9Kj5FYybKZPG=2FJUzTgbPcMVw4FwiXeaX0Bg?= =?us-ascii?Q?Mmu+LvYKmHllPJIqOMrS1r23PIA27kyc4gQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95138 Subject: [ruby-core:95138] [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 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/