Project

General

Profile

Bug #15658

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

Added by mame (Yusuke Endoh) 4 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
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.

Associated revisions

Revision 76fc1ce0
Added by mame (Yusuke Endoh) 4 months ago

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

Revert r64358. [Bug #15658]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67217
Added by mame (Yusuke Endoh) 4 months ago

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

Revert r64358. [Bug #15658]

Revision dca69588
Added by naruse (Yui NARUSE) 4 months ago

merge revision(s) 67217: [Backport #15658]

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

    Revert r64358.  [Bug #15658]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67220
Added by naruse (Yui NARUSE) 4 months ago

merge revision(s) 67217: [Backport #15658]

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

Revert r64358.  [Bug #15658]

History

#1

Updated by mame (Yusuke Endoh) 4 months 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) 4 months 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.

#3

Updated by usa (Usaku NAKAMURA) 3 months ago

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

Also available in: Atom PDF