Skip to content

Commit a91ffcf

Browse files
matzclaude
andcommitted
mruby-compiler: fix as-pattern parsing with symbol values
Remove non-standard `symbol tASSOC p_as` rule from hash pattern elements. This rule conflicted with the as-pattern rule and caused `:foo => x` to be incorrectly parsed as a hash pattern instead of an as-pattern. CRuby only supports label syntax (foo:) for hash pattern keys, not hashrocket syntax (:foo =>). This change aligns mruby with CRuby behavior and reduces bison shift-reduce conflicts from 2 to 1. Before: `case :foo; in :foo => x; end` raised NoMethodError After: `case :foo; in :foo => x; end` binds x to :foo Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4fc81e8 commit a91ffcf

2 files changed

Lines changed: 3213 additions & 3328 deletions

File tree

mrbgems/mruby-compiler/core/parse.y

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,6 +4133,7 @@ p_hash_elems : p_hash_elem
41334133

41344134
/* Hash pattern element: key: pattern or key: (shorthand) */
41354135
/* Use p_as, not p_expr to avoid brace-less recursion inside hash patterns */
4136+
/* Note: CRuby only supports label syntax (foo:), not hashrocket (:foo =>) */
41364137
p_hash_elem : tIDENTIFIER tLABEL_TAG p_as
41374138
{
41384139
/* {key: pattern} */
@@ -4143,11 +4144,6 @@ p_hash_elem : tIDENTIFIER tLABEL_TAG p_as
41434144
/* {key:} shorthand - binds to variable with same name */
41444145
$$ = cons(new_sym(p, $1), new_pat_var(p, $1));
41454146
}
4146-
| symbol tASSOC p_as
4147-
{
4148-
/* {:"key" => pattern} or {:key => pattern} */
4149-
$$ = cons($1, $3);
4150-
}
41514147
;
41524148

41534149
/* Keyword rest pattern: **var, **nil, or ** */

0 commit comments

Comments
 (0)