Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRISM] Fix case splat with no predicate #9582

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,17 @@ def self.prism_test_case_node
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
Expand All @@ -866,6 +877,16 @@ def self.prism_test_case_node
:ok
end
RUBY

# test splat with no predicate
assert_prism_eval(<<~RUBY)
case
when *[true]
:ok
else
:ng
end
RUBY
end

def test_ElseNode
Expand Down