Project

General

Profile

Feature #16355 ยป expr-in-pat-raises-error.patch

ktsj (Kazuki Tsujimoto), 11/20/2019 12:58 AM

View differences:

compile.c
l1 = NEW_LABEL(line);
ADD_LABEL(body_seq, l1);
ADD_INSN(body_seq, line, pop);
ADD_TRACE_BRANCH_COVERAGE(
body_seq,
node->nd_body ? nd_first_lineno(node->nd_body) : lineno,
node->nd_body ? nd_first_column(node->nd_body) : column,
node->nd_body ? nd_last_lineno(node->nd_body) : last_lineno,
node->nd_body ? nd_last_column(node->nd_body) : last_column,
"in",
branches);
CHECK(COMPILE_(body_seq, "in body", node->nd_body, popped));
if (node->nd_body) {
ADD_INSN(body_seq, line, pop);
ADD_TRACE_BRANCH_COVERAGE(
body_seq,
nd_first_lineno(node->nd_body),
nd_first_column(node->nd_body),
nd_last_lineno(node->nd_body),
nd_last_column(node->nd_body),
"in",
branches);
CHECK(COMPILE_(body_seq, "in body", node->nd_body, popped));
}
else {
/* Single line pattern matching(`expr in pat`). Returns the value of expr. */
ADD_TRACE_BRANCH_COVERAGE(body_seq, lineno, column, last_lineno, last_column, "in", branches);
}
ADD_INSNL(body_seq, line, jump, endlabel);
pattern = node->nd_head;
parse.y
{
p->in_kwarg = !!$<num>3;
/*%%%*/
$$ = NEW_CASE3($1, NEW_IN($5, NEW_TRUE(&@5), NEW_FALSE(&@5), &@5), &@$);
$$ = NEW_CASE3($1, NEW_IN($5, Qnull, Qnull, &@5), &@$);
rb_warn0L(nd_line($$), "Pattern matching is experimental, and the behavior may change in future versions of Ruby!");
/*% %*/
/*% ripper: case!($1, in!($5, Qnil, Qnil)) %*/
test/ruby/test_pattern_matching.rb
################################################################
def test_modifier_in
assert_equal true, (1 in a)
assert_equal 1, (1 in a)
assert_raise(NoMatchingPatternError) do
1 in 2
end
assert_equal 1, a
assert_valid_syntax "p(({} in {a:}), a:\n 1)"
assert_syntax_error(%q{
    (1-1/1)