summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2026-05-04 21:31:57 +0900
committernagachika <nagachika@ruby-lang.org>2026-05-04 21:31:57 +0900
commitfdac94eee1a3f226cafcfa6ec0da97bb08b03369 (patch)
treec5f3e5482504a0c276a77b2940d144e3c328b28c
parentc1487868e98300c6decc6b84f4867624efb53c5a (diff)
merge revision(s) 7f4f3c8ee7cde795dc27be753796fc7ea8318565: [Backport #22004]
[PATCH] [Bug #22004] Fix short-circuited loop conditions
-rw-r--r--compile.c2
-rw-r--r--test/ruby/test_iseq.rb4
-rw-r--r--version.h2
3 files changed, 7 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index 99a0d69903..2421b9c8e1 100644
--- a/compile.c
+++ b/compile.c
@@ -4699,6 +4699,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));
@@ -4708,6 +4709,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 68d83747b1..bb79f63960 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -862,6 +862,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)
diff --git a/version.h b/version.h
index 739b2d1548..f53bbdd8b3 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 9
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 83
+#define RUBY_PATCHLEVEL 84
#include "ruby/version.h"
#include "ruby/internal/abi.h"