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

This commit is contained in:
wanabe 2020-08-08 11:29:51 +09:00
Родитель ce7a053475
Коммит 65ae7f347a
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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')