Skip to content

Commit

Permalink
[PRISM] Account for ImplicitRestNode
Browse files Browse the repository at this point in the history
Prism introduced a new ImplicitRestNode. This adds tests for the
ImplicitRestNode cases, and changes one assert which is no longer
accurate.
  • Loading branch information
jemmaissroff committed Nov 29, 2023
1 parent 5384194 commit 2233204
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 1 addition & 4 deletions prism_compile.c
Expand Up @@ -3313,14 +3313,11 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
PM_DUP_UNLESS_POPPED;

pm_node_t *rest_expression = NULL;
if (multi_write_node->rest) {
RUBY_ASSERT(PM_NODE_TYPE_P(multi_write_node->rest, PM_SPLAT_NODE));

if (multi_write_node->rest && PM_NODE_TYPE_P(multi_write_node->rest, PM_SPLAT_NODE)) {
pm_splat_node_t *rest_splat = ((pm_splat_node_t *)multi_write_node->rest);
rest_expression = rest_splat->expression;
}


if (lefts->size) {
ADD_INSN2(ret, &dummy_line_node, expandarray, INT2FIX(lefts->size), INT2FIX((int) (bool) (rights->size || rest_expression)));
for (size_t index = 0; index < lefts->size; index++) {
Expand Down
8 changes: 6 additions & 2 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -435,6 +435,7 @@ def test_MultiTargetNode

def test_MultiWriteNode
assert_prism_eval("foo, bar = [1, 2]")
assert_prism_eval("foo, = [1, 2]")
assert_prism_eval("foo, *, bar = [1, 2]")
assert_prism_eval("foo, bar = 1, 2")
assert_prism_eval("foo, *, bar = 1, 2")
Expand Down Expand Up @@ -679,8 +680,9 @@ def test_ForNode
assert_prism_eval("for @i in [1,2] do; @i; end")
assert_prism_eval("for $i in [1,2] do; $i; end")

# TODO: multiple assignment in ForNode index
#assert_prism_eval("for i, j in {a: 'b'} do; i; j; end")
assert_prism_eval("for foo, in [1,2,3] do end")

assert_prism_eval("for i, j in {a: 'b'} do; i; j; end")
end

############################################################################
Expand Down Expand Up @@ -766,6 +768,8 @@ def test_BlockNode
assert_prism_eval("[1, 2, 3].each { |num| num }")

assert_prism_eval("[].tap { _1 }")

assert_prism_eval("[].each { |a,| }")
end

def test_ClassNode
Expand Down

0 comments on commit 2233204

Please sign in to comment.