diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-28 13:44:25 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-28 13:47:14 +0900 |
commit | 8b4ee5d6ba92a385eedc9235ce0a2d5618deecf0 (patch) | |
tree | cc994e8656fe3fbbdb828eb3d0ce8842731ea49e | |
parent | 18953416def52824c46a68370c4b34f5b720ee3f (diff) |
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]
-rw-r--r-- | parse.y | 2 | ||||
-rw-r--r-- | test/ruby/test_pattern_matching.rb | 5 |
2 files changed, 5 insertions, 2 deletions
@@ -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)) %*/ diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index 889f8dd519..50bab51bfa 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -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 |