diff options
author | Jemma Issroff <jemmaissroff@gmail.com> | 2023-11-29 15:50:46 -0500 |
---|---|---|
committer | Jemma Issroff <jemmaissroff@gmail.com> | 2023-11-29 16:14:28 -0500 |
commit | 2233204cc17521b960dad8b3758e6e0631a13672 (patch) | |
tree | 79015797aff734d574d41221634e5127c8dbf0f8 | |
parent | 53841941f0e9bce92116c673e3d5426d94573103 (diff) | |
download | ruby-2233204cc17521b960dad8b3758e6e0631a13672.tar.gz |
[PRISM] Account for ImplicitRestNode
Prism introduced a new ImplicitRestNode. This adds tests for the
ImplicitRestNode cases, and changes one assert which is no longer
accurate.
-rw-r--r-- | prism_compile.c | 5 | ||||
-rw-r--r-- | test/ruby/test_compile_prism.rb | 8 |
2 files changed, 7 insertions, 6 deletions
diff --git a/prism_compile.c b/prism_compile.c index ab3fc79818..ca416547bb 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -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++) { diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 394f7d2646..7614abb628 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -435,6 +435,7 @@ module Prism 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") @@ -679,8 +680,9 @@ module Prism 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 ############################################################################ @@ -766,6 +768,8 @@ module Prism assert_prism_eval("[1, 2, 3].each { |num| num }") assert_prism_eval("[].tap { _1 }") + + assert_prism_eval("[].each { |a,| }") end def test_ClassNode |