diff --git a/parse.y b/parse.y index 8314f07759..f0f2f8bbf9 100644 --- a/parse.y +++ b/parse.y @@ -3955,12 +3955,17 @@ p_expr_basic : p_value $$ = new_array_pattern_tail(p, Qnone, 0, 0, Qnone, &@$); $$ = new_array_pattern(p, Qnone, Qnone, $$, &@$); } - | tLBRACE {$$ = push_pktbl(p);} p_kwargs '}' + | tLBRACE + { + $$ = push_pktbl(p); + p->in_kwarg = 0; + } + p_kwargs rbrace { pop_pktbl(p, $2); $$ = new_hash_pattern(p, Qnone, $3, &@$); } - | tLBRACE '}' + | tLBRACE rbrace { $$ = new_hash_pattern_tail(p, Qnone, 0, &@$); $$ = new_hash_pattern(p, Qnone, $$, &@$); @@ -5420,6 +5425,9 @@ rparen : opt_nl ')' rbracket : opt_nl ']' ; +rbrace : opt_nl '}' + ; + trailer : /* none */ | '\n' | ',' diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index a3b7dcfd18..f9217aa7da 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1051,6 +1051,20 @@ END end end + assert_block do + case {a: 0} + in {a: 1 + } + false + in {a: + 2} + false + in {a: + } + true + end + end + assert_syntax_error(%q{ case _ in "a-b":