diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2026-05-11 13:45:55 -0700 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2026-05-11 13:45:55 -0700 |
| commit | b18acb27c3f1b1ae26bbae6e53e94e246dc0e973 (patch) | |
| tree | da03413acce54659cf19a7a67c7801e2f89194b5 | |
| parent | b00545b9652782b5ab07d16dc7729b0c69242d3c (diff) | |
merge revision(s) 7f4f3c8ee7cde795dc27be753796fc7ea8318565: [Backport #22004]
[PATCH] [Bug #22004] Fix short-circuited loop conditions
| -rw-r--r-- | compile.c | 2 | ||||
| -rw-r--r-- | test/ruby/test_iseq.rb | 4 |
2 files changed, 6 insertions, 0 deletions
@@ -4844,6 +4844,7 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *cond, CHECK(ok = compile_logical(iseq, ret, RNODE_AND(cond)->nd_1st, NULL, else_label)); cond = RNODE_AND(cond)->nd_2nd; if (ok == COMPILE_SINGLE) { + ADD_INSNL(ret, cond, jump, else_label); INIT_ANCHOR(ignore); ret = ignore; then_label = NEW_LABEL(nd_line(cond)); @@ -4853,6 +4854,7 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *cond, CHECK(ok = compile_logical(iseq, ret, RNODE_OR(cond)->nd_1st, then_label, NULL)); cond = RNODE_OR(cond)->nd_2nd; if (ok == COMPILE_SINGLE) { + ADD_INSNL(ret, cond, jump, then_label); INIT_ANCHOR(ignore); ret = ignore; else_label = NEW_LABEL(nd_line(cond)); diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index c43fc32b59..9235ef3f5b 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -875,6 +875,10 @@ class TestISeq < Test::Unit::TestCase assert_ruby_status([], "BEGIN {exit}; while true && true; end") end + def test_short_circuited_loop_condition + assert_ruby_status([], "while true || true; exit; end; abort") + end + def test_unreachable_syntax_error mesg = /Invalid break/ assert_syntax_error("false and break", mesg) |
