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 711EC1F463 for ; Fri, 27 Sep 2019 23:04:06 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 292C5120A5C; Sat, 28 Sep 2019 08:03:58 +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 34AC0120A1E for ; Sat, 28 Sep 2019 08:03:55 +0900 (JST) Received: by filter0135p3las1.sendgrid.net with SMTP id filter0135p3las1-6680-5D8E955E-3F 2019-09-27 23:03:58.36980794 +0000 UTC m=+358792.943364916 Received: from herokuapp.com (unknown [54.167.110.97]) by ismtpd0067p1mdw1.sendgrid.net (SG) with ESMTP id HLIcG2IIR66oZ4OgkQYkSg for ; Fri, 27 Sep 2019 23:03:58.207 +0000 (UTC) Date: Fri, 27 Sep 2019 23:03:58 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70694 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16166 X-Redmine-Issue-Author: sawa 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?BI=2FxI9YbOa6anIfKRtTto7MH+bfS4X93Wixfgn1?= =?us-ascii?Q?bUEE1kObhtypkbi5fJjFNRvDFIc3Z4rL+BR07RY?= =?us-ascii?Q?UcmQy2rZUaaSo+Dv584Dqk8YcPt9il0PNxHhFXp?= =?us-ascii?Q?9JUsfNjF3NN5FGaYJLrTTnf4NCKc45j8aGA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95139 Subject: [ruby-core:95139] [Ruby master Feature#16166] Remove exceptional treatment of *foo when it is the sole block parameter 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 #16166 has been updated by jeremyevans0 (Jeremy Evans). matz (Yukihiro Matsumoto) wrote: > I think the following code behavior is wrong: > ```ruby > p instance_exec(["a"]){|*foo, **bar| foo } #=> ["a"] > ``` > It should return `[["a"]]`. Here's a pull request for that: https://github.com/ruby/ruby/pull/2502 Note that it breaks some tests/specs. I believe the reason methods with keywords were handled differently is because the last element of the argument could be used as keywords: ``` $ ruby -e "p proc{|*foo, **bar| [foo, bar]}.call([1, {a: 1}])" -e:1: warning: The last argument is used as the keyword parameter -e:1: warning: for `call' defined here [[1], {:a=>1}] ``` As you can see, this now raises a warning in Ruby 2.7, and behavior will change in Ruby 3.0. Do we want to make this change in 2.7, or do we want to wait for 3.0? ---------------------------------------- Feature #16166: Remove exceptional treatment of *foo when it is the sole block parameter https://bugs.ruby-lang.org/issues/16166#change-81778 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- In the parameter signature of a code block for a method that is not involved in method definition or creation of lambda objects, two types of arguments `["a"]` and `"a"` are neutralized: ```ruby instance_exec(["a"]){|foo, bar| foo} # => "a" instance_exec("a"){|foo, bar| foo} # => "a" instance_exec(["a"]){|*foo, **bar| foo} # => ["a"] instance_exec("a"){|*foo, **bar| foo} # => ["a"] ``` This is the same behavior as with assignment constructions: ```ruby foo, bar = ["a"]; foo # => "a" foo, bar = "a"; foo # => "a" *foo = ["a"]; foo # => ["a"] *foo = "a"; foo # => ["a"] ``` And it contrasts with constructions involved in method definition or creation of lambda objects, where the distinction is preserved: ```ruby lambda{|foo| foo}.call(["a"]) # => ["a"] lambda{|foo| foo}.call("a") # => "a" ->(foo){foo}.call(["a"]) # => ["a"] ->(foo){foo}.call("a") # => "a" lambda{|*foo| foo}.call(["a"]) # => [["a"]] lambda{|*foo| foo}.call("a") # => ["a"] ->(*foo){foo}.call(["a"]) # => [["a"]] ->(*foo){foo}.call("a") # => ["a"] ``` However, when `*foo` is the sole parameter of a code block for a method that is not involved in method definition or creation of lambda objects, `["a"]` and `"a"` are not neutralized: ```ruby instance_exec(["a"]){|*foo| foo} # => [["a"]] instance_exec("a"){|*foo| foo} # => ["a"] ``` behaving in contrast to assignment constructions, and rather on a par with constructions involved in method definition or creation of lambda objects. Particularly, existence or absence of another parameter `**bar` entirely changes what `foo` refers to: ```ruby instance_exec(["a"]){|*foo| foo} # => [["a"]] instance_exec(["a"]){|*foo, **bar| foo} # => ["a"] ``` I find this behavior inconsistent and confusing. I would like to request to remove this exceptional treatment of splatted parameter `*foo` when it is the sole parameter in a code block. I request this behavior: ```ruby instance_exec(["a"]){|*foo| foo} # => ["a"] ``` -- https://bugs.ruby-lang.org/