Project

General

Profile

Actions

Bug #15658

closed

The combination of non-Symbol keys and Symbol keys should be allowed

Added by mame (Yusuke Endoh) about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Target version:
-
[ruby-core:91779]

Description

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.

Actions #1

Updated by mame (Yusuke Endoh) about 5 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r67217.


The combination of non-Symbol keys and Symbol keys is now allowed again

Revert r64358. [Bug #15658]

Updated by naruse (Yui NARUSE) about 5 years ago

  • 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.

Actions #3

Updated by usa (Usaku NAKAMURA) almost 5 years ago

  • Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: DONE to 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0