[PRISM] Fix case splat with no predicate
This commit is contained in:
parent
686b1655a0
commit
8a3e7f08b8
@ -3514,10 +3514,11 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
||||
pm_node_t *condition_node = when_node->conditions.nodes[i];
|
||||
|
||||
if (PM_NODE_TYPE_P(condition_node, PM_SPLAT_NODE)) {
|
||||
int checkmatch_type = has_predicate ? VM_CHECKMATCH_TYPE_CASE : VM_CHECKMATCH_TYPE_WHEN;
|
||||
ADD_INSN (ret, &dummy_line_node, dup);
|
||||
PM_COMPILE_NOT_POPPED(condition_node);
|
||||
ADD_INSN1(ret, &dummy_line_node, splatarray, Qfalse);
|
||||
ADD_INSN1(ret, &dummy_line_node, checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
|
||||
ADD_INSN1(ret, &dummy_line_node, checkmatch,
|
||||
INT2FIX(checkmatch_type | VM_CHECKMATCH_ARRAY));
|
||||
}
|
||||
else {
|
||||
PM_COMPILE_NOT_POPPED(condition_node);
|
||||
|
@ -857,6 +857,17 @@ module Prism
|
||||
end
|
||||
RUBY
|
||||
|
||||
# Test splat in when
|
||||
assert_prism_eval(<<~RUBY)
|
||||
ary = [1, 2]
|
||||
case 1
|
||||
when :foo, *ary
|
||||
:ok
|
||||
else
|
||||
:ng
|
||||
end
|
||||
RUBY
|
||||
|
||||
# Test case without predicate
|
||||
assert_prism_eval(<<~RUBY)
|
||||
case
|
||||
@ -866,6 +877,16 @@ module Prism
|
||||
:ok
|
||||
end
|
||||
RUBY
|
||||
|
||||
# test splat with no predicate
|
||||
assert_prism_eval(<<~RUBY)
|
||||
case
|
||||
when *[true]
|
||||
:ok
|
||||
else
|
||||
:ng
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
def test_ElseNode
|
||||
|
Loading…
x
Reference in New Issue
Block a user