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