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 8F68A1F4C0 for ; Mon, 21 Oct 2019 16:56:30 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 900F21209EE; Tue, 22 Oct 2019 01:56:20 +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 779991209DB for ; Tue, 22 Oct 2019 01:56:18 +0900 (JST) Received: by filter0048p3iad2.sendgrid.net with SMTP id filter0048p3iad2-6943-5DADE332-5C 2019-10-21 16:56:18.677664251 +0000 UTC m=+316506.942733339 Received: from herokuapp.com (unknown [54.159.77.90]) by ismtpd0024p1mdw1.sendgrid.net (SG) with ESMTP id tsUaZw86SDiz6FmartN5Hg for ; Mon, 21 Oct 2019 16:56:18.524 +0000 (UTC) Date: Mon, 21 Oct 2019 16:56:18 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71050 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 12106 X-Redmine-Issue-Author: pabloh X-Redmine-Issue-Assignee: nobu 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?BIkEq+icwKopXa4TuIhG9WXCHYINLE8es+LTq2e?= =?us-ascii?Q?ufm+D1czfyQd4=2FWLGt+T6rnKpdymMSXurwEseCc?= =?us-ascii?Q?YUiHKyzvj7tauo085BOELJufv4WZpefuCRL7oyP?= =?us-ascii?Q?PO6veZ23KtFd94ZtqQyLrT9PY7TOP56hpdw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95459 Subject: [ruby-core:95459] [Ruby master Bug#12106] Behavior of double splatting of hashes with non symbol key is different according to splatted hash position 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 #12106 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Assigned to Closed With the changes in #14183, TypeError is no longer raised in any of the examples, as non-Symbol keys can be used inside a hash that is double splatted. ---------------------------------------- Bug #12106: Behavior of double splatting of hashes with non symbol key is different according to splatted hash position https://bugs.ruby-lang.org/issues/12106#change-82211 * Author: pabloh (Pablo Herrero) * Status: Closed * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Target version: * ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- When doing double splatting with hash with non symbols keys you get different behaviors according to the position of the hash been splatted: ```ruby {a: 3, **{b: 1}, **{'b' => 1}} # Works fine {a: 3, **{1 => 1}, **{b: 1}} # Works fine {3 => 3, **{b: 1}, **{'b' => 1}} # Works fine {**{}, a: 3, **{b: 1}, **{1 => 1}} # Works fine {**{b: 1}, a: 3, **{1 => 1}} # TypeError: wrong argument type Fixnum (expected Symbol) {**{'b' => 1}, **{c: 4}} # TypeError: wrong argument type Fixnum (expected Symbol) {**{c: 4}, **{'b' => 1}} # TypeError: wrong argument type Fixnum (expected Symbol) {**{c: 4}, a: 3, **{'b' => 1}} # TypeError: wrong argument type Fixnum (expected Symbol) ``` Same thing happens when you double splat inside a message send: ```ruby puts(a: 3, **{b: 1}, **{'b' => 1}) # Works fine puts(a: 3, **{1 => 1}, **{b: 1}) # Works fine puts(3 => 3, **{b: 1}, **{'b' => 1}) # Works fine puts(**{}, a: 3, **{b: 1}, **{1 => 1}) # Works fine puts(**{b: 1}, a: 3, **{1 => 1}) # TypeError: wrong argument type Fixnum (expected Symbol) puts(**{'b' => 1}, **{c: 4}) # TypeError: wrong argument type Fixnum (expected Symbol) puts(**{c: 4}, **{'b' => 1}) # TypeError: wrong argument type Fixnum (expected Symbol) puts(**{c: 4}, a: 3, **{'b' => 1}) # TypeError: wrong argument type Fixnum (expected Symbol) ``` What's basically going on is this: you can double splat hashes with no symbol keys all you want, only if the first value of the hash is a regular key (symbol or not) and not a splatted hash, or also a double splatted empty hash. It feels strange that building the same hash in different orders yields so different behaviors. Anyhow, I personally feel it should be a bug if you cannot splat a hash with no symbol keys into another one, whichever are the remaining values of the hash. -- https://bugs.ruby-lang.org/