From 163947f4dc031bb5e619ae64ad4a6a02f8885717 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 10 Sep 2022 16:00:29 +0900 Subject: merge revision(s) db0e0dad1171456253ebd899e7e878823923d3d8: [Backport #18990] 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(-) --- parse.y | 16 ++++++++++++---- test/ruby/test_pattern_matching.rb | 12 ++++++++++++ version.h | 4 ++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/parse.y b/parse.y index 4e05bfd672..e3e680414a 100644 --- a/parse.y +++ b/parse.y @@ -1762,14 +1762,18 @@ expr : command_call p->ctxt.in_kwarg = 1; $$ = push_pvtbl(p); } + { + $$ = push_pktbl(p); + } p_top_expr_body { + pop_pktbl(p, $4); pop_pvtbl(p, $3); p->ctxt.in_kwarg = $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 { @@ -1780,14 +1784,18 @@ expr : command_call p->ctxt.in_kwarg = 1; $$ = push_pvtbl(p); } + { + $$ = push_pktbl(p); + } p_top_expr_body { + pop_pktbl(p, $4); pop_pvtbl(p, $3); p->ctxt.in_kwarg = $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 35c41eb8b6..4c203fb4f9 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1566,6 +1566,18 @@ END assert_experimental_warning("case [0]; in [*, 0, *]; end") 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 diff --git a/version.h b/version.h index 2b3f1d3ce5..83a5306811 100644 --- a/version.h +++ b/version.h @@ -11,11 +11,11 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 3 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 48 +#define RUBY_PATCHLEVEL 49 #define RUBY_RELEASE_YEAR 2022 #define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 4 +#define RUBY_RELEASE_DAY 10 #include "ruby/version.h" -- cgit v1.2.3