ruby-changes:73493
From: Kazuki <ko1@a...>
Date: Fri, 9 Sep 2022 14:05:18 +0900 (JST)
Subject: [ruby-changes:73493] db0e0dad11 (master): Fix unexpected "duplicated key name" error in paren-less one line pattern matching
https://git.ruby-lang.org/ruby.git/commit/?id=db0e0dad11 From db0e0dad1171456253ebd899e7e878823923d3d8 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto <kazuki@c...> Date: Fri, 9 Sep 2022 14:00:27 +0900 Subject: Fix unexpected "duplicated key name" error in paren-less one line pattern matching [Bug #18990] --- parse.y | 16 ++++++++++++---- test/ruby/test_pattern_matching.rb | 12 ++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/parse.y b/parse.y index e6fee29595..38f7690ccc 100644 --- a/parse.y +++ b/parse.y @@ -1774,14 +1774,18 @@ expr : command_call https://github.com/ruby/ruby/blob/trunk/parse.y#L1774 p->ctxt.in_kwarg = 1; $<tbl>$ = push_pvtbl(p); } + { + $<tbl>$ = push_pktbl(p); + } p_top_expr_body { + pop_pktbl(p, $<tbl>4); pop_pvtbl(p, $<tbl>3); p->ctxt.in_kwarg = $<ctxt>2.in_kwarg; /*%%%*/ - $$ = NEW_CASE3($1, NEW_IN($4, 0, 0, &@4), &@$); + $$ = NEW_CASE3($1, NEW_IN($5, 0, 0, &@5), &@$); /*% %*/ - /*% ripper: case!($1, in!($4, Qnil, Qnil)) %*/ + /*% ripper: case!($1, in!($5, Qnil, Qnil)) %*/ } | arg keyword_in { @@ -1792,14 +1796,18 @@ expr : command_call https://github.com/ruby/ruby/blob/trunk/parse.y#L1796 p->ctxt.in_kwarg = 1; $<tbl>$ = push_pvtbl(p); } + { + $<tbl>$ = push_pktbl(p); + } p_top_expr_body { + pop_pktbl(p, $<tbl>4); pop_pvtbl(p, $<tbl>3); p->ctxt.in_kwarg = $<ctxt>2.in_kwarg; /*%%%*/ - $$ = NEW_CASE3($1, NEW_IN($4, NEW_TRUE(&@4), NEW_FALSE(&@4), &@4), &@$); + $$ = NEW_CASE3($1, NEW_IN($5, NEW_TRUE(&@5), NEW_FALSE(&@5), &@5), &@$); /*% %*/ - /*% ripper: case!($1, in!($4, Qnil, Qnil)) %*/ + /*% ripper: case!($1, in!($5, Qnil, Qnil)) %*/ } | arg %prec tLBRACE_ARG ; diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index 36731e14f9..fbb934dc84 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1570,6 +1570,18 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pattern_matching.rb#L1570 assert_equal false, (1 in 2) end + def test_bug18990 + {a: 0} => a: + assert_equal 0, a + {a: 0} => a: + assert_equal 0, a + + {a: 0} in a: + assert_equal 0, a + {a: 0} in a: + assert_equal 0, a + end + ################################################################ def test_single_pattern_error_value_pattern -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/