ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:92647] [Ruby trunk Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior
       [not found] <redmine.issue-15849.20190514183938@ruby-lang.org>
@ 2019-05-14 18:39 ` jared_smartt_92
  2019-05-14 18:51 ` [ruby-core:92648] " merch-redmine
  2019-07-29  7:01 ` [ruby-core:93968] [Ruby master " ko1
  2 siblings, 0 replies; 3+ messages in thread
From: jared_smartt_92 @ 2019-05-14 18:39 UTC (permalink / raw)
  To: ruby-core

Issue #15849 has been reported by jsmartt (Jared Smartt).

----------------------------------------
Bug #15849: Using hash as first positional argument, mixed with named arguments causes unexpected behavior
https://bugs.ruby-lang.org/issues/15849

* Author: jsmartt (Jared Smartt)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
If the first argument of a method defaults to an empty hash, and there is another keyword argument after it, it does not set first parameter given to the first argument

For example:

``` ruby
data = {}
# This method does not modify the data hash as expected
def add_to_data(data = {}, key: 'a')
  data[key] = 'value'
end
add_to_data(data)
puts data   # {}
```

Trying the following produces an error:

```ruby
data = { b: 'val' }
add_to_data(data)   # ERROR: unknown keyword: b (ArgumentError)
```

There are a lot of other similar combinations of this method definition that do work as expected. It appears that having a default value for that first positional argument is what causes issues; see the attached script.

---Files--------------------------------
ruby_named_param_bug.rb (1.2 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:92648] [Ruby trunk Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior
       [not found] <redmine.issue-15849.20190514183938@ruby-lang.org>
  2019-05-14 18:39 ` [ruby-core:92647] [Ruby trunk Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior jared_smartt_92
@ 2019-05-14 18:51 ` merch-redmine
  2019-07-29  7:01 ` [ruby-core:93968] [Ruby master " ko1
  2 siblings, 0 replies; 3+ messages in thread
From: merch-redmine @ 2019-05-14 18:51 UTC (permalink / raw)
  To: ruby-core

Issue #15849 has been updated by jeremyevans0 (Jeremy Evans).


I believe this is the same issue as #12717. We are trying to address this issue in #14183.

----------------------------------------
Bug #15849: Using hash as first positional argument, mixed with named arguments causes unexpected behavior
https://bugs.ruby-lang.org/issues/15849#change-78010

* Author: jsmartt (Jared Smartt)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
If the first argument of a method defaults to an empty hash, and there is another keyword argument after it, it does not set first parameter given to the first argument

For example:

``` ruby
data = {}
# This method does not modify the data hash as expected
def add_to_data(data = {}, key: 'a')
  data[key] = 'value'
end
add_to_data(data)
puts data   # {}
```

Trying the following produces an error:

```ruby
data = { b: 'val' }
add_to_data(data)   # ERROR: unknown keyword: b (ArgumentError)
```

There are a lot of other similar combinations of this method definition that do work as expected. It appears that having a default value for that first positional argument is what causes issues; see the attached script.

---Files--------------------------------
ruby_named_param_bug.rb (1.2 KB)


-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:93968] [Ruby master Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior
       [not found] <redmine.issue-15849.20190514183938@ruby-lang.org>
  2019-05-14 18:39 ` [ruby-core:92647] [Ruby trunk Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior jared_smartt_92
  2019-05-14 18:51 ` [ruby-core:92648] " merch-redmine
@ 2019-07-29  7:01 ` ko1
  2 siblings, 0 replies; 3+ messages in thread
From: ko1 @ 2019-07-29  7:01 UTC (permalink / raw)
  To: ruby-core

Issue #15849 has been updated by ko1 (Koichi Sasada).

Status changed from Open to Closed

I believe Jeremy :) and if it is not the same issue, please reopen it.


----------------------------------------
Bug #15849: Using hash as first positional argument, mixed with named arguments causes unexpected behavior
https://bugs.ruby-lang.org/issues/15849#change-80159

* Author: jsmartt (Jared Smartt)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
If the first argument of a method defaults to an empty hash, and there is another keyword argument after it, it does not set first parameter given to the first argument

For example:

``` ruby
data = {}
# This method does not modify the data hash as expected
def add_to_data(data = {}, key: 'a')
  data[key] = 'value'
end
add_to_data(data)
puts data   # {}
```

Trying the following produces an error:

```ruby
data = { b: 'val' }
add_to_data(data)   # ERROR: unknown keyword: b (ArgumentError)
```

There are a lot of other similar combinations of this method definition that do work as expected. It appears that having a default value for that first positional argument is what causes issues; see the attached script.

---Files--------------------------------
ruby_named_param_bug.rb (1.2 KB)


-- 
https://bugs.ruby-lang.org/

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

end of thread, other threads:[~2019-07-29  7:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15849.20190514183938@ruby-lang.org>
2019-05-14 18:39 ` [ruby-core:92647] [Ruby trunk Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior jared_smartt_92
2019-05-14 18:51 ` [ruby-core:92648] " merch-redmine
2019-07-29  7:01 ` [ruby-core:93968] [Ruby master " ko1

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