ruby-changes:65224
From: nagachika <ko1@a...>
Date: Thu, 11 Feb 2021 12:52:34 +0900 (JST)
Subject: [ruby-changes:65224] c271c7a225 (ruby_2_7): merge revision(s) ce7a053475cbebfb2f3e5ed6614e0ba631541917,1cbb1f1720127b0b34b38c77e27b51b182008699: [Backport #16695]
https://git.ruby-lang.org/ruby.git/commit/?id=c271c7a225 From c271c7a225c6175f56f00b785e3034cb4a2b7658 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Thu, 11 Feb 2021 12:52:11 +0900 Subject: merge revision(s) ce7a053475cbebfb2f3e5ed6614e0ba631541917,1cbb1f1720127b0b34b38c77e27b51b182008699: [Backport #16695] Adjust sp for `x = false; y = (return until x unless x)` [Bug #16695] --- compile.c | 8 +++----- test/ruby/test_syntax.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) test/ruby/test_syntax.rb: avoid "warning: assigned but unused variable" --- test/ruby/test_syntax.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- compile.c | 8 +++----- test/ruby/test_syntax.rb | 9 +++++++++ version.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compile.c b/compile.c index 5f86a5b..c05a4a0 100644 --- a/compile.c +++ b/compile.c @@ -2737,7 +2737,6 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L2737 goto again; } else if (IS_INSN_ID(diobj, leave)) { - INSN *pop; /* * jump LABEL * ... @@ -2745,7 +2744,6 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L2744 * leave * => * leave - * pop * ... * LABEL: * leave @@ -2755,9 +2753,6 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L2753 iobj->insn_id = BIN(leave); iobj->operand_size = 0; iobj->insn_info = diobj->insn_info; - /* adjust stack depth */ - pop = new_insn_body(iseq, diobj->insn_info.line_no, BIN(pop), 0); - ELEM_INSERT_NEXT(&iobj->link, &pop->link); goto again; } else if (IS_INSN(iobj->link.prev) && @@ -5247,6 +5242,9 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int https://github.com/ruby/ruby/blob/trunk/compile.c#L5242 branches); end_label = NEW_LABEL(line); ADD_INSNL(then_seq, line, jump, end_label); + if (!popped) { + ADD_INSN(then_seq, line, pop); + } } ADD_SEQ(ret, then_seq); } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index f628dc3..86417ba 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1374,6 +1374,15 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1374 assert_nil obj.test end + def test_assignment_return_in_loop + obj = Object.new + def obj.test + x = nil + _y = (return until x unless x) + end + assert_nil obj.test, "[Bug #16695]" + end + def test_method_call_location line = __LINE__+5 e = assert_raise(NoMethodError) do diff --git a/version.h b/version.h index 9d7c1f8..798bfeb 100644 --- a/version.h +++ b/version.h @@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 3 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 149 +#define RUBY_PATCHLEVEL 150 #define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_MONTH 2 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/