diff options
| author | Jemma Issroff <jemmaissroff@gmail.com> | 2023-12-07 10:08:16 -0500 |
|---|---|---|
| committer | Jemma Issroff <jemmaissroff@gmail.com> | 2023-12-07 10:34:39 -0500 |
| commit | b8df6b9e01d8971235ea42fc9098ce392f791928 (patch) | |
| tree | 04acf865693f8a6d287bfd043af23babbf613b09 | |
| parent | cbc0e0bef08f9389f5bbe76de016795f01c3bc76 (diff) | |
[PRISM] Don't pop arguments on a return node
Since ReturnNodes don't get popped, their arguments shouldn't either
| -rw-r--r-- | prism_compile.c | 5 | ||||
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 9 |
2 files changed, 11 insertions, 3 deletions
diff --git a/prism_compile.c b/prism_compile.c index 1371ef9c5a..e5a82b37e1 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3941,7 +3941,6 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, if (iseq) { enum rb_iseq_type type = ISEQ_BODY(iseq)->type; - const NODE *retval = RNODE_RETURN(node)->nd_stts; LABEL *splabel = 0; const rb_iseq_t *parent_iseq = iseq; @@ -3954,7 +3953,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, switch (parent_type) { case ISEQ_TYPE_TOP: case ISEQ_TYPE_MAIN: - if (retval) { + if (arguments) { rb_warn("argument of top-level return is ignored"); } if (parent_iseq == iseq) { @@ -3972,7 +3971,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, } if (arguments) { - PM_COMPILE((pm_node_t *)arguments); + PM_COMPILE_NOT_POPPED((pm_node_t *)arguments); } else { PM_PUTNIL; diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 97ee5c2f70..42e2ebbf00 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -1009,6 +1009,15 @@ module Prism end prism_test_return_node CODE + assert_prism_eval(<<-CODE) + def self.prism_test_return_node + [1].map do |i| + return i if i == 1 + 2 + end + end + prism_test_return_node + CODE end ############################################################################ |
