ruby-changes:60540
From: Kazuki <ko1@a...>
Date: Sat, 28 Mar 2020 06:14:14 +0900 (JST)
Subject: [ruby-changes:60540] 93aaa0bcce (ruby_2_7): Allow trailing comma in hash pattern
https://git.ruby-lang.org/ruby.git/commit/?id=93aaa0bcce From 93aaa0bcce829b880d8f52a9168d17c93ecde85b Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto <kazuki@c...> Date: Sun, 1 Mar 2020 14:23:51 +0900 Subject: Allow trailing comma in hash pattern (cherry picked from commit d25a4f413dce6ad3a8baaf61591415b9a8cce082) diff --git a/parse.y b/parse.y index c767637..b1a7e08 100644 --- a/parse.y +++ b/parse.y @@ -4053,6 +4053,10 @@ p_kwargs : p_kwarg ',' p_kwrest https://github.com/ruby/ruby/blob/trunk/parse.y#L4053 { $$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), 0, &@$); } + | p_kwarg ',' + { + $$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), 0, &@$); + } | p_kwrest { $$ = new_hash_pattern_tail(p, new_hash(p, Qnone, &@$), $1, &@$); diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index 6dbb25c..a3b7dcf 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1042,6 +1042,15 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pattern_matching.rb#L1042 end end + assert_block do + case {a: 0, b: 1} + in {a: 1,} + false + in {a:,} + true + end + end + assert_syntax_error(%q{ case _ in "a-b": -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/