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

Distinct last positional argument hashes from keywords on Ruby 3 #537

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Mar 18, 2022

This is a solution attempt for #536

On Ruby 3 we can (with effort) distinguish between a last positional hash and a keyword hash, because the mixed behaviour we can get on other Rubies shouldn't happen.


# If we don't allow the keyword splat, and the last hash contains extra keys
# then it is a positional hash.
return false if !@allows_any_kw_args && has_extra_keys
Copy link
Member

Choose a reason for hiding this comment

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

I guess there's a problem between 2.7 and 3.0+ with (spec/rspec/support/method_signature_verifier_spec.rb:372)

> def arity_kw(x, y = {}, z:2); end

> arity_kw(nil, {a: 1}, {z: 2})

it works fine on 2.7 but fails on 3.0+:

ArgumentError: wrong number of arguments (given 3, expected 1..2)

To me, it seems that this expectation is not justified on Ruby 2.7:

expect(valid?(nil, :a => 1)).to eq(false)

as y is initialized with {:a => 1}.

I didn't look at other few failing examples yet.

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