Skip to content

Commit

Permalink
- builders/default: allow forwarded_kwrestarg with additional kwargs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
owst authored Mar 7, 2023
1 parent 1e7a4b2 commit ff6f75a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/parser/builders/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,13 @@ def kwsplat(dstar_t, arg)
def associate(begin_t, pairs, end_t)
0.upto(pairs.length - 1) do |i|
(i + 1).upto(pairs.length - 1) do |j|
key1, = *pairs[i]
key2, = *pairs[j]
pair_i = pairs[i]
pair_j = pairs[j]

next if pair_i.type != :pair || pair_j.type != :pair

key1, = *pair_i
key2, = *pair_j

do_warn = false

Expand Down
26 changes: 26 additions & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10958,6 +10958,32 @@ def test_forwarded_kwrestarg
SINCE_3_2)
end

def test_forwarded_kwrestarg_with_additional_kwarg
assert_parses(
s(:def, :foo,
s(:args,
s(:kwrestarg)),
s(:send, nil, :bar,
s(:kwargs,
s(:forwarded_kwrestarg),
s(:pair,
s(:sym, :from_foo),
s(:true))))),
%q{def foo(**); bar(**, from_foo: true); end},
%q{ ~~ expression (send.kwargs.forwarded_kwrestarg)},
SINCE_3_2)

refute_diagnoses(
%q{def foo(**); bar(**, from_foo: true); end},
SINCE_3_2)

assert_diagnoses(
[:warning, :duplicate_hash_key],
%q{def foo(**); bar(foo: 1, **, foo: 2); end},
%q{ ^^^ location},
SINCE_3_2)
end

def test_forwarded_argument_with_kwrestarg
assert_parses(
s(:def, :foo,
Expand Down

0 comments on commit ff6f75a

Please sign in to comment.