ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: merch-redmine@jeremyevans.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:96631] [Ruby master Bug#16473] New deprecated warning disallows keyword arguments bypassing
Date: Thu, 02 Jan 2020 17:31:15 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-83601.20200102173114.1c0b411480cfe22a@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16473.20200102171037@ruby-lang.org

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

Status changed from Open to Rejected

This behavior is expected.  The positional hash argument is converted to keyword arguments when `kw` is called.  That is not going to work in Ruby 3 (see #14183), hence the warning.

For delegating argument to a method that accepts keywords, you should probably use `ruby2_keywords` (if you also need to support older ruby versions):

```ruby
ruby2_keywords :non_kw if respond_to?(:ruby2_keywords, true)
```

----------------------------------------
Bug #16473: New deprecated warning disallows keyword arguments bypassing
https://bugs.ruby-lang.org/issues/16473#change-83601

* Author: puchuu (Andrew Aladjev)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.

```ruby
def kw(a: 1)
  puts "kw #{a}"
end

def non_kw(a = {}, *args)
  puts "non kw #{a}"
  kw *args
end

non_kw({ :a => 2 }, :a => 2)
non_kw({ :a => 3 })
non_kw
```

The right output is:

```
non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
```

Ruby 2.7.0 provides deprecated warning:
```ruby
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

`*args` is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.



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

  parent reply	other threads:[~2020-01-02 17:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
2020-01-02 17:10 ` [ruby-core:96628] [Ruby master Bug#16473] New deprecated warning disallows arguments bypassing aladjev.andrew
2020-01-02 17:31 ` merch-redmine [this message]
2020-01-02 17:55 ` [ruby-core:96632] [Ruby master Bug#16473] New deprecated warning disallows keyword " aladjev.andrew
2020-01-02 18:10 ` [ruby-core:96633] " merch-redmine
2020-01-02 23:08 ` [ruby-core:96637] " daniel
2020-01-02 23:29 ` [ruby-core:96638] " eregontp

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-83601.20200102173114.1c0b411480cfe22a@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).