1
0
Fork 0
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:
Nobuyoshi Nakada 2019-11-28 13:44:25 +09:00
parent 18953416de
commit 8b4ee5d6ba
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 5 additions and 2 deletions

View file

@ -1571,7 +1571,7 @@ expr : command_call
{
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!");
/*% %*/
/*% ripper: case!($1, in!($5, Qnil, Qnil)) %*/

View file

@ -1261,8 +1261,11 @@ END
################################################################
def test_modifier_in
assert_equal true, (1 in a)
assert_nil (1 in 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_syntax_error(%q{
1 in a, b