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.9 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 3847A1F462 for ; Mon, 29 Jul 2019 07:01:36 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3611A1209E5; Mon, 29 Jul 2019 16:01:30 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 64430120A7D for ; Mon, 29 Jul 2019 16:01:28 +0900 (JST) Received: by filter0052p3iad2.sendgrid.net with SMTP id filter0052p3iad2-23336-5D3E99C7-43 2019-07-29 07:01:27.825372686 +0000 UTC m=+215806.102155370 Received: from herokuapp.com (unknown [3.80.72.87]) by ismtpd0038p1mdw1.sendgrid.net (SG) with ESMTP id 18CW4rTQRA63axtjWTR7aw for ; Mon, 29 Jul 2019 07:01:27.722 +0000 (UTC) Date: Mon, 29 Jul 2019 07:01:27 +0000 (UTC) From: ko1@atdot.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69473 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15849 X-Redmine-Issue-Author: jsmartt 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?fVTMYOBjtdvXNcWwrscBhLsHItUXVK5L4mtnq0mdcRf0UhF8uzXeBfaTT1tYBI?= =?us-ascii?Q?pTNzhlm=2F=2FzKo3ymFWMqo03B+1wjIo+hURLi1dpB?= =?us-ascii?Q?oaA6E+YIB2My4HcArxUbXhsq+GX3JOPG60ihbKD?= =?us-ascii?Q?VusL93D0HgrVf+IrQUDQ0Ctxh9B4C1dl4LyLfR5?= =?us-ascii?Q?2p4kKWAMykrE2?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93968 Subject: [ruby-core:93968] [Ruby master Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior 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 #15849 has been updated by ko1 (Koichi Sasada). Status changed from Open to Closed I believe Jeremy :) and if it is not the same issue, please reopen it. ---------------------------------------- Bug #15849: Using hash as first positional argument, mixed with named arguments causes unexpected behavior https://bugs.ruby-lang.org/issues/15849#change-80159 * Author: jsmartt (Jared Smartt) * Status: Closed * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- If the first argument of a method defaults to an empty hash, and there is another keyword argument after it, it does not set first parameter given to the first argument For example: ``` ruby data = {} # This method does not modify the data hash as expected def add_to_data(data = {}, key: 'a') data[key] = 'value' end add_to_data(data) puts data # {} ``` Trying the following produces an error: ```ruby data = { b: 'val' } add_to_data(data) # ERROR: unknown keyword: b (ArgumentError) ``` There are a lot of other similar combinations of this method definition that do work as expected. It appears that having a default value for that first positional argument is what causes issues; see the attached script. ---Files-------------------------------- ruby_named_param_bug.rb (1.2 KB) -- https://bugs.ruby-lang.org/