From: naruse@... Date: 2019-03-11T12:59:51+00:00 Subject: [ruby-core:91781] [Ruby trunk Bug#15658] The combination of non-Symbol keys and Symbol keys should be allowed Issue #15658 has been updated by naruse (Yui NARUSE). Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: REQUIRED to 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: DONE ruby_2_6 r67220 merged revision(s) 67217. ---------------------------------------- Bug #15658: The combination of non-Symbol keys and Symbol keys should be allowed https://bugs.ruby-lang.org/issues/15658#change-77056 * Author: mame (Yusuke Endoh) * Status: Closed * Priority: Normal * Assignee: mame (Yusuke Endoh) * Target version: * ruby -v: * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: DONE ---------------------------------------- It was prohibited at 2.6.0 and 2.6.1 to pass both non-Symbol keys and Symbol-keys simultaneously: ``` def foo(opt=nil, **kw) p opt, kw end foo("str" => 42, :sym => 42) #=> 2.5.3: {"str"=>42}, {:sym=>42} #=> 2.6.0: non-symbol key in keyword arguments: "str" (ArgumentError) ``` However, at today's developers meeting, we found this change problematic. I'll revert the change soon, and will be backported to 2.6.2. Rationale: To accept the mixed arguments, we can use an optional argument now: ``` def foo(opt={}) p opt end foo("str" => 42, :sym => 42) #=> works as intended: { "str" => 42, :sym => 42 } ``` However, this might not work in 3.0: it is now considered to completely separate keyword arguments from positional arguments (#14183). We will be able to use `def foo(**opt)` in the situation in 3.0 because 3.0's `**kw` parameter will allow non-Symbol key. However, if we want a code that works in both 2.5 and 3.0, we need "manual merge": ``` def foo(opt={}, **kw) opt = opt.merge(kw) ... end ``` However, this code does not work in 2.6.1 because it is prohibited. #14183 is not determined yet, but anyway, we found that this prohibition required more careful consideration than we had expected. So, we cancel the prohibition once, and will reconsider the problem carefully. -- https://bugs.ruby-lang.org/ Unsubscribe: