ruby-changes:47069
From: nobu <ko1@a...>
Date: Tue, 27 Jun 2017 23:09:14 +0900 (JST)
Subject: [ruby-changes:47069] nobu:r59184 (trunk): fix return in toplevel ensure
nobu 2017-06-27 23:09:08 +0900 (Tue, 27 Jun 2017) New Revision: 59184 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59184 Log: fix return in toplevel ensure * compile.c (iseq_compile_each0): adjust stack after return in toplevel ensure, when the value is used. [ruby-core:81777] [Bug #13682] Modified files: trunk/compile.c trunk/test/ruby/test_syntax.rb Index: compile.c =================================================================== --- compile.c (revision 59183) +++ compile.c (revision 59184) @@ -4824,8 +4824,6 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L4824 CHECK(COMPILE_POPPED(ensr, "ensure ensr", node->nd_ensr)); last = ensr->last; last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave); - if (!popped && last_leave) - popped = 1; er.begin = lstart; er.end = lend; @@ -4833,13 +4831,16 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L4831 push_ensure_entry(iseq, &enl, &er, node->nd_ensr); ADD_LABEL(ret, lstart); - CHECK(COMPILE_(ret, "ensure head", node->nd_head, popped)); + CHECK(COMPILE_(ret, "ensure head", node->nd_head, (popped | last_leave))); ADD_LABEL(ret, lend); if (ensr->anchor.next == NULL) { ADD_INSN(ret, line, nop); } else { ADD_SEQ(ret, ensr); + if (!popped && last_leave) { + ADD_INSN(ret, line, putnil); + } } ADD_LABEL(ret, lcont); if (last_leave) ADD_INSN(ret, line, pop); Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 59183) +++ test/ruby/test_syntax.rb (revision 59184) @@ -977,6 +977,7 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L977 "#{return}" raise((return; "should not raise")) begin raise; ensure return; end; self + begin raise; ensure return; end and self end; all_assertions(feature4840) do |a| code.each_line do |s| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/