diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2024-01-22 13:52:41 -0500 |
|---|---|---|
| committer | Aaron Patterson <aaron.patterson@gmail.com> | 2024-01-22 15:07:52 -0800 |
| commit | 708fa7740479823e0758623d43afee7b13beba21 (patch) | |
| tree | c93a5ba2df16554c7757ee3df184d69fbac499aa | |
| parent | 1838dbf6e7f9335e5ad23d9856bd014d18446f07 (diff) | |
[PRISM] Fix keyword arguments in IndexOrWriteNode
Fixes ruby/prism#2236.
| -rw-r--r-- | prism_compile.c | 4 | ||||
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/prism_compile.c b/prism_compile.c index e5ba24115d..3fd9efbf0d 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1298,9 +1298,9 @@ pm_compile_index_and_or_write_node(bool and_node, pm_node_t *receiver, pm_node_t ADD_INSNL(ret, &dummy_line_node, jump, lfin); ADD_LABEL(ret, label); if (!popped) { - ADD_INSN1(ret, &dummy_line_node, setn, FIXNUM_INC(argc, 2 + block_offset)); + ADD_INSN1(ret, &dummy_line_node, setn, FIXNUM_INC(argc, 2 + block_offset + (keywords ? keywords->keyword_len : 0))); } - ADD_INSN1(ret, &dummy_line_node, adjuststack, FIXNUM_INC(argc, 2 + block_offset)); + ADD_INSN1(ret, &dummy_line_node, adjuststack, FIXNUM_INC(argc, 2 + block_offset + (keywords ? keywords->keyword_len : 0))); ADD_LABEL(ret, lfin); return; diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index fd5787e467..f54097ab66 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -425,6 +425,15 @@ module Prism hash CODE + # Test with keyword arguments + assert_prism_eval(<<~RUBY) + h = Object.new + def h.[](**b) = 0 + def h.[]=(*a, **b); end + + h[foo: 1] ||= 2 + RUBY + # Test with keyword splat assert_prism_eval(<<~RUBY) h = Object.new |
