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

Fix Kernel#warn override #2911

Merged
3 commits merged into from
Sep 26, 2019
Merged

Conversation

jeremyevans
Copy link
Contributor

Description:

This makes the Kernel#warn override behave the same as the default
Kernel#warn. Previously, behavior could be different, because an
empty hash or empty keyword arguments would be swallowed by the
override, and the second to last argument could be treated as the
keyword argument by the default Kernel#warn.

For example:

warn({x:1}, {y:2}, {})

# C version outputs:
{:x=>1}
{:y=>2}

# Rubygems version raises:
unknown keyword: y (ArgumentError)

By using a keyword splat, and passing the keyword splat to the
default version, we can make behavior the same.

This issue was originally reported on the Ruby bug tracker:
https://bugs.ruby-lang.org/issues/16157#note-8

Tasks:

  • Describe the problem / feature
  • Write tests
  • Write code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Sep 12, 2019

Hi @jeremyevans! Thanks for the fix.

I added a second commit that should fix the failing test (coming from #2442 for context) and a regression test for your fix. What do you think?

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Sep 12, 2019

mmmm.

Ruby-head build is failing 👉 https://travis-ci.org/rubygems/rubygems/jobs/584028540. That's using a ruby from a week ago (ruby 2.7.0dev (2019-09-05T13:16:21Z trunk 433c9c0) [x86_64-linux])

But it's passing for me locally against a more recent version (ruby 2.7.0dev (2019-09-09T12:27:40Z master 89c5d5a) [x86_64-linux]).

Has something change in the last week regarding this? 🤔.

@jeremyevans
Copy link
Contributor Author

@deivid-rodriguez Thanks for working on the regression test, this looks good to me.

I think your approach when uplevel is provided is better. My approach had a bug where the new uplevel would be overridden by the originally provided one.

JRuby 9.2 treats an empty keyword hash as uplevel 0 instead of no uplevel, which I'm guessing is the reason that you aren't sending keywords on JRuby in the first call. That seems like a bug in JRuby, I'll report it upstream.

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Sep 12, 2019

Nice @jeremyevans!

Yeah, there was one failing test on jruby, so I figured we should keep the implementation unchanged on jruby for now. Even if it's currently buggy, at least don't make it worse. I subscribed to your jruby issue so I remember to remove the conditional once they fix this.

What about the ruby-head failure? The regression test is failing precisely with the error we're supposed to be fixing here, so I'm confused 😕.

@jeremyevans
Copy link
Contributor Author

ruby-head no longer sends an empty hash to C functions (or Ruby methods that do not accept keywords) if using an empty keyword splat when calling the method. rb_scan_args needs to be fixed so that it does not handle the last hash argument as keywords if an empty splat is provided. I started working on a patch for rb_scan_args yesterday, which I think will fix the issue.

@deivid-rodriguez
Copy link
Member

I rebased this PR, precisely to check how it is doing against ruby-head (since it was passing for me locally against ruby 2.7.0dev (2019-09-09T12:27:40Z master 89c5d5a), and our CI no longer depends on TravisCI upgrading its ruby-head installation.

But CI doesn't seem to have been triggered.

@hbst Any ideas?

jeremyevans and others added 3 commits September 25, 2019 11:40
This makes the Kernel#warn override behave the same as the default
Kernel#warn.  Previously, behavior could be different, because an
empty hash or empty keyword arguments would be swallowed by the
override, and the second to last argument could be treated as the
keyword argument by the default Kernel#warn.

For example:

    warn({x:1}, {y:2}, {})

    # C version outputs:
    {:x=>1}
    {:y=>2}

    # Rubygems version raises:
    unknown keyword: y (ArgumentError)

By using a keyword splat, and passing the keyword splat to the
default version, we can make behavior the same.
And test the fix we're adding.
@hsbt
Copy link
Member

hsbt commented Sep 26, 2019

Umm, We couldn't care the ruby-head version on Travis. If we hope to test the latest head version, We can use https://github.com/ruby/ruby-docker-images with GitHub Actions.

I try to switch it from RVM later.

@hsbt
Copy link
Member

hsbt commented Sep 26, 2019

@bundlerbot r+

ghost pushed a commit that referenced this pull request Sep 26, 2019
2911: Fix Kernel#warn override r=hsbt a=jeremyevans

# Description:

This makes the Kernel#warn override behave the same as the default
Kernel#warn.  Previously, behavior could be different, because an
empty hash or empty keyword arguments would be swallowed by the
override, and the second to last argument could be treated as the
keyword argument by the default Kernel#warn.

For example:

    warn({x:1}, {y:2}, {})

    # C version outputs:
    {:x=>1}
    {:y=>2}

    # Rubygems version raises:
    unknown keyword: y (ArgumentError)

By using a keyword splat, and passing the keyword splat to the
default version, we can make behavior the same.

This issue was originally reported on the Ruby bug tracker:
https://bugs.ruby-lang.org/issues/16157#note-8

# Tasks:

- [X] Describe the problem / feature
- [ ] Write tests
- [X] Write code to solve the problem
- [ ] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).

Co-authored-by: Jeremy Evans <code@jeremyevans.net>
Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
@ghost
Copy link

ghost commented Sep 26, 2019

Build succeeded

@ghost ghost merged commit cc255b7 into rubygems:master Sep 26, 2019
@hsbt hsbt mentioned this pull request Sep 26, 2019
4 tasks
ghost pushed a commit that referenced this pull request Oct 10, 2019
2931: Pick missing changes at #2911 r=hsbt a=hsbt

# Description:

@jeremyevans This is the missing commit at #2911 from ruby/ruby@80b5a0f

______________

# Tasks:

- [ ] Describe the problem / feature
- [ ] Write tests
- [ ] Write code to solve the problem
- [ ] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).


Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
hsbt added a commit that referenced this pull request Oct 15, 2019
2931: Pick missing changes at #2911 r=hsbt a=hsbt

# Description:

@jeremyevans This is the missing commit at #2911 from ruby/ruby@80b5a0f

______________

# Tasks:

- [ ] Describe the problem / feature
- [ ] Write tests
- [ ] Write code to solve the problem
- [ ] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).


Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
This pull request was closed.
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.

4 participants