Skip to content

Commit 7f4f3c8

Browse files
committed
[Bug #22004] Fix short-circuited loop conditions
1 parent c9b5347 commit 7f4f3c8

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4843,6 +4843,7 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *cond,
48434843
CHECK(ok = compile_logical(iseq, ret, RNODE_AND(cond)->nd_1st, NULL, else_label));
48444844
cond = RNODE_AND(cond)->nd_2nd;
48454845
if (ok == COMPILE_SINGLE) {
4846+
ADD_INSNL(ret, cond, jump, else_label);
48464847
INIT_ANCHOR(ignore);
48474848
ret = ignore;
48484849
then_label = NEW_LABEL(nd_line(cond));
@@ -4852,6 +4853,7 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *cond,
48524853
CHECK(ok = compile_logical(iseq, ret, RNODE_OR(cond)->nd_1st, then_label, NULL));
48534854
cond = RNODE_OR(cond)->nd_2nd;
48544855
if (ok == COMPILE_SINGLE) {
4856+
ADD_INSNL(ret, cond, jump, then_label);
48554857
INIT_ANCHOR(ignore);
48564858
ret = ignore;
48574859
else_label = NEW_LABEL(nd_line(cond));

test/ruby/test_iseq.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ def test_ever_condition_loop
906906
assert_ruby_status([], "BEGIN {exit}; while true && true; end")
907907
end
908908

909+
def test_short_circuited_loop_condition
910+
assert_ruby_status([], "while true || true; exit; end; abort")
911+
end
912+
909913
def test_unreachable_syntax_error
910914
mesg = /Invalid break/
911915
assert_syntax_error("false and break", mesg)

0 commit comments

Comments
 (0)