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+ #1

Closed
wants to merge 1 commit into from

Conversation

lewispb
Copy link
Member

@lewispb lewispb commented Jan 7, 2022

Bringing in this from upstream: brianmario#1084 to give us Ruby 3 compatibility.

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
```
@lewispb lewispb requested a review from jeremy January 7, 2022 10:45
Copy link
Member

@jeremy jeremy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewispb I'll merge upstream into the fork! Generally doing that rather than pulling in specific changes.

@lewispb
Copy link
Member Author

lewispb commented Jan 10, 2022

Perfect, thanks @jeremy

@lewispb lewispb closed this Jan 10, 2022
@jeremy
Copy link
Member

jeremy commented Jan 10, 2022

Merged and pushed to mysql2 0.5.4.latin1utf8 to geminabox.

lewispb pushed a commit that referenced this pull request Mar 31, 2023
Only do version check in Windows environment
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.

3 participants