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.2 required=3.0 tests=BAYES_00,FORGED_HOTMAIL_RCVD2, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,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 02D021F461 for ; Tue, 14 May 2019 18:39:46 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 54C9C1208D1; Wed, 15 May 2019 03:39: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 78E411208CE for ; Wed, 15 May 2019 03:39:38 +0900 (JST) Received: by filter0126p3las1.sendgrid.net with SMTP id filter0126p3las1-28619-5CDB0B6A-30 2019-05-14 18:39:38.844250686 +0000 UTC m=+88461.818710412 Received: from herokuapp.com (unknown [52.72.240.185]) by ismtpd0030p1iad2.sendgrid.net (SG) with ESMTP id _b2VIvtZRPSQu5MlMKJXTw for ; Tue, 14 May 2019 18:39:38.914 +0000 (UTC) Date: Tue, 14 May 2019 18:39:39 +0000 (UTC) From: jared_smartt_92@hotmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68130 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15849 X-Redmine-Issue-Author: jsmartt X-Redmine-Sender: jsmartt 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?3N61DGpG7StiKAIDNOkSJNWcmAh4DgTn2aQoDn7Zyf7KgvtiDVmEcnpvMvhRWr?= =?us-ascii?Q?u++A6U5E+XNaXp3CWFLMjJ9jXy8dUzyNevkRYvx?= =?us-ascii?Q?+S09wsZCaK5FnWeEE9LJlBJH7DnbWI2TlpLroD0?= =?us-ascii?Q?6UXRZ23kdbsErieS9ID1difcPge9TcKYDImR5u5?= =?us-ascii?Q?3d8xmNhLdIimF612J+qRcicDo8fwEISCjNg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92647 Subject: [ruby-core:92647] [Ruby trunk 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 reported by jsmartt (Jared Smartt). ---------------------------------------- Bug #15849: Using hash as first positional argument, mixed with named arguments causes unexpected behavior https://bugs.ruby-lang.org/issues/15849 * Author: jsmartt (Jared Smartt) * Status: Open * 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/