Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

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

Closed
wants to merge 1 commit into 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.

@JonRowe
Copy link
Member Author

JonRowe commented Nov 30, 2024

Migrated to the monorepo as rspec/rspec#120

@JonRowe JonRowe closed this Nov 30, 2024
@JonRowe JonRowe deleted the improve-keyword-support-in-method-signature branch November 30, 2024 11:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants