ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91779] [Ruby trunk Bug#15658] The combination of non-Symbol keys and Symbol keys should be allowed
       [not found] <redmine.issue-15658.20190311124624@ruby-lang.org>
@ 2019-03-11 12:48 ` mame
  2019-03-11 12:59 ` [ruby-core:91781] " naruse
  1 sibling, 0 replies; 2+ messages in thread
From: mame @ 2019-03-11 12:48 UTC (permalink / raw)
  To: ruby-core

Issue #15658 has been reported by mame (Yusuke Endoh).

----------------------------------------
Bug #15658: The combination of non-Symbol keys and Symbol keys should be allowed
https://bugs.ruby-lang.org/issues/15658

* Author: mame (Yusuke Endoh)
* Status: Assigned
* Priority: Normal
* Assignee: mame (Yusuke Endoh)
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: REQUIRED
----------------------------------------
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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:91781] [Ruby trunk Bug#15658] The combination of non-Symbol keys and Symbol keys should be allowed
       [not found] <redmine.issue-15658.20190311124624@ruby-lang.org>
  2019-03-11 12:48 ` [ruby-core:91779] [Ruby trunk Bug#15658] The combination of non-Symbol keys and Symbol keys should be allowed mame
@ 2019-03-11 12:59 ` naruse
  1 sibling, 0 replies; 2+ messages in thread
From: naruse @ 2019-03-11 12:59 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-11 12:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15658.20190311124624@ruby-lang.org>
2019-03-11 12:48 ` [ruby-core:91779] [Ruby trunk Bug#15658] The combination of non-Symbol keys and Symbol keys should be allowed mame
2019-03-11 12:59 ` [ruby-core:91781] " naruse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).