From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id D23611A000FD for ; Wed, 24 Feb 2016 12:58:05 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id D90AFB5D897 for ; Wed, 24 Feb 2016 13:33:20 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 435F118CC7CC for ; Wed, 24 Feb 2016 13:33:21 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5C622120464; Wed, 24 Feb 2016 13:33:20 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id B7DA3120450 for ; Wed, 24 Feb 2016 13:33:16 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=lMZTcbU+rryRjuc0T02FRRCDI3w=; b=GUk7ZdVFnZmDj62vZM BdngLYPrVhtIJx4sesNLQzdFEMAVLFSWhtcml5Bfzo0lYTzhoqkaYjtU+gBRy5eW dOmwSHRCnJeqBSiFn+HVnlV7NQsp2YX7u38bQByx2JvTQZ+fkhd4Wru8bnhcvhGG JjX5sRjkE7XdeK90Lpfwr9T0c= Received: by filter0825p1mdw1.sendgrid.net with SMTP id filter0825p1mdw1.7977.56CD328428 2016-02-24 04:33:08.61432724 +0000 UTC Received: from herokuapp.com (ec2-54-205-15-91.compute-1.amazonaws.com [54.205.15.91]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id XxKchlieTKSwGZIj_nBKZw for ; Wed, 24 Feb 2016 04:33:08.636 +0000 (UTC) Date: Wed, 24 Feb 2016 04:33:08 +0000 From: pablodherrero@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 48560 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 12106 X-Redmine-Issue-Author: pabloh X-Redmine-Sender: pabloh 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: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5w5mXSdoyVSKICWjIzu3wjdf0EhVVAEvlmiC VdKlMu98iFKVbaRAj+pLej7ED826OcLrLU2ONGoBAtA3ndfMQENSC+5T9oWd0CKULv7E81PMpo9Sh0 4Tqr0goXfS68SpT334cqvqR2fY8sN3JUpnOj6WMtwlPZD4KvdAZspYEEDQ== X-ML-Name: ruby-core X-Mail-Count: 73958 Subject: [ruby-core:73958] [Ruby trunk 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 Pablo Herrero. Small correction: for the 2nd, 3rd and 4th examples the error actually is "# TypeError: wrong argument type String (expected Symbol)" ---------------------------------------- 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-57107 * Author: Pablo Herrero * Status: Open * Priority: Normal * Assignee: * 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/