From: merch-redmine@jeremyevans.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:92648] [Ruby trunk Bug#15849] Using hash as first positional argument, mixed with named arguments causes unexpected behavior
Date: Tue, 14 May 2019 18:51:26 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-78010.20190514185126.00a6ac5f49025e35@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15849.20190514183938@ruby-lang.org
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/
next prev parent reply other threads:[~2019-05-14 18:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 [this message]
2019-07-29 7:01 ` [ruby-core:93968] [Ruby master " ko1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-78010.20190514185126.00a6ac5f49025e35@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).