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.4 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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 8A20620248 for ; Mon, 11 Mar 2019 05:17:20 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 1CB11120976; Mon, 11 Mar 2019 14:17:16 +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 B2BE1121ECF for ; Mon, 11 Mar 2019 14:17:13 +0900 (JST) Received: by filter0082p3las1.sendgrid.net with SMTP id filter0082p3las1-31245-5C85EF18-5 2019-03-11 05:16:08.141665328 +0000 UTC m=+190583.239765708 Received: from herokuapp.com (unknown [54.173.53.240]) by ismtpd0065p1mdw1.sendgrid.net (SG) with ESMTP id ZPD9lzlBTy-AmoCbuZTGkw for ; Mon, 11 Mar 2019 05:16:08.001 +0000 (UTC) Date: Mon, 11 Mar 2019 05:17:12 +0000 (UTC) From: ko1@atdot.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 67198 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15620 X-Redmine-Issue-Author: alanwu X-Redmine-Issue-Assignee: matz X-Redmine-Sender: ko1 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?fVTMYOBjtdvXNcWwrscBhLsHItUXVK5L4mtnq0mdcRcNrOsiYnm1JkaQnep7Rh?= =?us-ascii?Q?VV=2FYlo5Lehgs0M898lAvPTBpBedw8p78G1SB4YN?= =?us-ascii?Q?Br+qlFUJ10P7a9bzuC4bbdoQNONsY6fAHZN8lbO?= =?us-ascii?Q?ozacVCRFW=2F0bp=2Fcz5co0i9nXlBsEgZsT08ftfb3?= =?us-ascii?Q?Svtr1HyGEACtX?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 91748 Subject: [ruby-core:91748] [Ruby trunk Bug#15620] Block argument usage affects lambda semantic 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 #15620 has been updated by ko1 (Koichi Sasada). we will fix it. ---------------------------------------- Bug #15620: Block argument usage affects lambda semantic https://bugs.ruby-lang.org/issues/15620#change-77024 * Author: alanwu (Alan Wu) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: * ruby -v: * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- The following snippet demonstrate the issue: ``` ruby def pass_after_use(&block) raise unless block lambda(&block).call end def direct_pass(&block) lambda(&block).call end pass_after_use do |_arg| puts "fine, because block is materialized into a Proc before it is passed to #lambda" end direct_pass do |_arg| puts "Raises because all args are required. This is not printed" end ``` Output: ``` fine, because block is materialized into a Proc before it is passed to #lambda Traceback (most recent call last): 2: from lambda-block-pass.rb:14:in `
' 1: from lambda-block-pass.rb:7:in `direct_pass' lambda-block-pass.rb:14:in `block in
': wrong number of arguments (given 0, expected 1) (ArgumentError) ``` I think having the line `raise unless block` affect `Kenrel#lambda`'s semantic is pretty surprising. Note that if I do `raise unless block_given?`, call to the lambda without arg also raises. If I was to decide, I would always have the resulting lambda have required arguments even after multiple levels of block pass. That is, as long as the original block is a literal block. This is either a breaking change or a regression from 2.4. The same script executes without raising in 2.4.5 (block arguments are always materialized). -- https://bugs.ruby-lang.org/