mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 13:34:17 +02:00
[PRISM] Fix keyword splat in IndexAndWriteNode and IndexOrWriteNode
Fixes ruby/prism#2232 and ruby/prism#2234.
This commit is contained in:
parent
ab99ce910c
commit
dbd76d9101
2 changed files with 29 additions and 0 deletions
|
@ -952,6 +952,17 @@ pm_compile_index_write_nodes_add_send(bool popped, LINK_ANCHOR *const ret, rb_is
|
||||||
}
|
}
|
||||||
ADD_SEND_WITH_FLAG(ret, &dummy_line_node, idASET, argc, INT2FIX(flag));
|
ADD_SEND_WITH_FLAG(ret, &dummy_line_node, idASET, argc, INT2FIX(flag));
|
||||||
}
|
}
|
||||||
|
else if (flag & VM_CALL_KW_SPLAT) {
|
||||||
|
if (block_offset > 0) {
|
||||||
|
ADD_INSN1(ret, &dummy_line_node, topn, INT2FIX(2));
|
||||||
|
PM_SWAP;
|
||||||
|
ADD_INSN1(ret, &dummy_line_node, setn, INT2FIX(3));
|
||||||
|
PM_POP;
|
||||||
|
}
|
||||||
|
|
||||||
|
ADD_INSN(ret, &dummy_line_node, swap);
|
||||||
|
ADD_SEND_R(ret, &dummy_line_node, idASET, FIXNUM_INC(argc, 1), NULL, INT2FIX(flag), keywords);
|
||||||
|
}
|
||||||
else if (keywords && keywords->keyword_len) {
|
else if (keywords && keywords->keyword_len) {
|
||||||
ADD_INSN1(ret, &dummy_line_node, opt_reverse, INT2FIX(keywords->keyword_len + block_offset + 1));
|
ADD_INSN1(ret, &dummy_line_node, opt_reverse, INT2FIX(keywords->keyword_len + block_offset + 1));
|
||||||
ADD_INSN1(ret, &dummy_line_node, opt_reverse, INT2FIX(keywords->keyword_len + block_offset + 0));
|
ADD_INSN1(ret, &dummy_line_node, opt_reverse, INT2FIX(keywords->keyword_len + block_offset + 0));
|
||||||
|
|
|
@ -394,6 +394,15 @@ module Prism
|
||||||
|
|
||||||
h[foo: 1] &&= 2
|
h[foo: 1] &&= 2
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
|
# Test with keyword splat
|
||||||
|
assert_prism_eval(<<~RUBY)
|
||||||
|
h = Object.new
|
||||||
|
def h.[](**b) = 1
|
||||||
|
def h.[]=(*a, **b); end
|
||||||
|
|
||||||
|
h[**{}] &&= 2
|
||||||
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_IndexOrWriteNode
|
def test_IndexOrWriteNode
|
||||||
|
@ -415,6 +424,15 @@ module Prism
|
||||||
hash["key", &(Proc.new { _1.upcase })] ||= "value"
|
hash["key", &(Proc.new { _1.upcase })] ||= "value"
|
||||||
hash
|
hash
|
||||||
CODE
|
CODE
|
||||||
|
|
||||||
|
# Test with keyword splat
|
||||||
|
assert_prism_eval(<<~RUBY)
|
||||||
|
h = Object.new
|
||||||
|
def h.[](**b) = nil
|
||||||
|
def h.[]=(*a, **b); end
|
||||||
|
|
||||||
|
h[**{}] ||= 2
|
||||||
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_IndexOperatorWriteNode
|
def test_IndexOperatorWriteNode
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue