mirror of
https://github.com/ruby/ruby.git
synced 2026-07-31 09:25:15 +08:00
merge revision(s) 7f4f3c8ee7cde795dc27be753796fc7ea8318565: [Backport #22004]
[PATCH] [Bug #22004] Fix short-circuited loop conditions
This commit is contained in:
parent
b00545b965
commit
b18acb27c3
@ -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));
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user