1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Adjust sp for if true or .../if false and ...

This commit is contained in:
wanabe 2020-08-08 11:29:51 +09:00
parent ce7a053475
commit 65ae7f347a
Notes: git 2020-10-16 08:37:46 +09:00
2 changed files with 13 additions and 2 deletions

View file

@ -3889,7 +3889,10 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co
LABEL *label = NEW_LABEL(nd_line(cond));
CHECK(compile_branch_condition(iseq, ret, cond->nd_1st, label,
else_label));
if (!label->refcnt) break;
if (!label->refcnt) {
ADD_INSN(ret, nd_line(cond), putnil);
break;
}
ADD_LABEL(ret, label);
cond = cond->nd_2nd;
goto again;
@ -3899,7 +3902,10 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co
LABEL *label = NEW_LABEL(nd_line(cond));
CHECK(compile_branch_condition(iseq, ret, cond->nd_1st, then_label,
label));
if (!label->refcnt) break;
if (!label->refcnt) {
ADD_INSN(ret, nd_line(cond), putnil);
break;
}
ADD_LABEL(ret, label);
cond = cond->nd_2nd;
goto again;

View file

@ -1514,6 +1514,11 @@ eom
assert_valid_syntax("tap {a = (break unless true)}")
end
def test_tautological_condition
assert_valid_syntax("def f() return if false and invalid; nil end")
assert_valid_syntax("def f() return unless true or invalid; nil end")
end
def test_argument_forwarding
assert_valid_syntax('def foo(...) bar(...) end')
assert_valid_syntax('def foo(...) end')