From b18acb27c3f1b1ae26bbae6e53e94e246dc0e973 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 11 May 2026 13:45:55 -0700 Subject: merge revision(s) 7f4f3c8ee7cde795dc27be753796fc7ea8318565: [Backport #22004] [PATCH] [Bug #22004] Fix short-circuited loop conditions --- compile.c | 2 ++ test/ruby/test_iseq.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/compile.c b/compile.c index bcf22243cf..cefe6c4c6a 100644 --- a/compile.c +++ b/compile.c @@ -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) -- cgit v1.2.3