mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Raise NoMatchingPatternError
when expr in
pat doesn't match
* `expr in pattern` should raise `NoMatchingError` when unmatched * `expr in pattern` should return `nil`. (this is unspecified, but this feature is experimental, at all) [Feature #16355]
This commit is contained in:
parent
18953416de
commit
8b4ee5d6ba
2 changed files with 5 additions and 2 deletions
2
parse.y
2
parse.y
|
@ -1571,7 +1571,7 @@ expr : command_call
|
||||||
{
|
{
|
||||||
p->in_kwarg = !!$<num>3;
|
p->in_kwarg = !!$<num>3;
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = NEW_CASE3($1, NEW_IN($5, NEW_TRUE(&@5), NEW_FALSE(&@5), &@5), &@$);
|
$$ = NEW_CASE3($1, NEW_IN($5, 0, 0, &@5), &@$);
|
||||||
rb_warn0L(nd_line($$), "Pattern matching is experimental, and the behavior may change in future versions of Ruby!");
|
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)) %*/
|
/*% ripper: case!($1, in!($5, Qnil, Qnil)) %*/
|
||||||
|
|
|
@ -1261,8 +1261,11 @@ END
|
||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
def test_modifier_in
|
def test_modifier_in
|
||||||
assert_equal true, (1 in a)
|
assert_nil (1 in a)
|
||||||
assert_equal 1, a
|
assert_equal 1, a
|
||||||
|
assert_raise(NoMatchingPatternError) do
|
||||||
|
{a: 1} in {a: 0}
|
||||||
|
end
|
||||||
assert_valid_syntax "p(({} in {a:}), a:\n 1)"
|
assert_valid_syntax "p(({} in {a:}), a:\n 1)"
|
||||||
assert_syntax_error(%q{
|
assert_syntax_error(%q{
|
||||||
1 in a, b
|
1 in a, b
|
||||||
|
|
Loading…
Add table
Reference in a new issue