Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword arguments have to be explicitly double-splatted in Ruby 2.7+ #1084

Merged
merged 3 commits into from
Nov 27, 2019

Conversation

kamipo
Copy link
Contributor

@kamipo kamipo commented Nov 21, 2019

The Ruby core team decided to introduce a slight incompatibility to
keyword arguments from Ruby 3.0, i.e. complete separation between
keyword arguments literal and Hash literal.

https://bugs.ruby-lang.org/issues/14183
ruby/ruby#2395

With that, current Ruby master warns when a Hash object was passed in as
keyword arguments:

$ ruby -ve 'def f(x: nil) p x; end; hash = {x: 1}; f(hash)'
ruby 2.7.0dev (2019-09-02T05:20:05Z master 83498854eb) [x86_64-darwin18]
warning: The last argument is used as the keyword parameter
warning: for `f' defined here
1

To eliminate this warning, we need to prefix a "double splat" (**) to
avoid ambiguity:

$ ruby -ve 'def f(x: nil) p x;end; hash = {x: 1}; f(**hash)'
ruby 2.7.0dev (2019-09-02T05:20:05Z master 83498854eb) [x86_64-darwin18]
1

See also:

/usr/local/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/error.rb:55: warning: The last argument is used as the keyword parameter
/usr/local/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/error.rb:94: warning: The last argument is used as the keyword parameter

The Ruby core team decided to introduce a slight incompatibility to
keyword arguments from Ruby 3.0, i.e. complete separation between
keyword arguments literal and Hash literal.

https://bugs.ruby-lang.org/issues/14183
ruby/ruby#2395

With that, current Ruby master warns when a Hash object was passed in as
keyword arguments:

```
$ ruby -ve 'def f(x: nil) p x; end; hash = {x: 1}; f(hash)'
ruby 2.7.0dev (2019-09-02T05:20:05Z master 83498854eb) [x86_64-darwin18]
warning: The last argument is used as the keyword parameter
warning: for `f' defined here
1
```

To eliminate this warning, we need to prefix a "double splat" (**) to
avoid ambiguity:

```
$ ruby -ve 'def f(x: nil) p x;end; hash = {x: 1}; f(**hash)'
ruby 2.7.0dev (2019-09-02T05:20:05Z master 83498854eb) [x86_64-darwin18]
1
```

See also:

* ruby-i18n/i18n#486
* https://buildkite.com/rails/rails/builds/63974#7fb9ad05-a745-4022-b634-aa3eb9042b11/6-1865

```
/usr/local/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/error.rb:55: warning: The last argument is used as the keyword parameter
/usr/local/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/error.rb:94: warning: The last argument is used as the keyword parameter
```
@sodabrew
Copy link
Collaborator

sodabrew commented Nov 26, 2019

Thanks, I also see this error from the ruby-head build, could you address this as well in the PR?

/home/travis/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.7.0/rubygems/version.rb:212:
  warning: deprecated Object#=~ is called on Integer; it always returns nil

I suspect the issue is either that the tests should not replace the packaged rubygems version, or should use something newer than 2.7.6?

@kamipo
Copy link
Contributor Author

kamipo commented Nov 27, 2019

Yeah, rubygems 2.7.6 is pretty old version, the fix rubygems/rubygems#2494 is included in newer version rubygems.
I've fixed the warning in this PR as d2a273f and b700550.

@sodabrew sodabrew merged commit cb49983 into brianmario:master Nov 27, 2019
@sodabrew sodabrew added this to the 0.5.3 milestone Nov 27, 2019
@kamipo kamipo deleted the kwargs branch November 27, 2019 04:31
kamipo pushed a commit to rails/rails that referenced this pull request Dec 14, 2019
* Update mysql2 to the latest version

Fixes keyword arguments warning:
brianmario/mysql2/pull/1084

Fixes taint mechanism deprecation warning:
brianmario/mysql2@785969f

* Update json to the latest version

Fixes warning from trying to access an uninitialized ivar, and
keyword arguments warning:

flori/json/commit/de14dea34074558dc671d7edc71513f0216ce21d
flori/json/commit/19da336333e63dc9dde7baea47b179e162b7568e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants