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>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-12-29 13:42:19 +09:00
parent 4fc81e8ea0
commit a91ffcfe0d
2 changed files with 3405 additions and 3520 deletions
+1 -5
View File
@@ -4133,6 +4133,7 @@ p_hash_elems : p_hash_elem
/* Hash pattern element: key: pattern or key: (shorthand) */
/* Use p_as, not p_expr to avoid brace-less recursion inside hash patterns */
/* Note: CRuby only supports label syntax (foo:), not hashrocket (:foo =>) */
p_hash_elem : tIDENTIFIER tLABEL_TAG p_as
{
/* {key: pattern} */
@@ -4143,11 +4144,6 @@ p_hash_elem : tIDENTIFIER tLABEL_TAG p_as
/* {key:} shorthand - binds to variable with same name */
$$ = cons(new_sym(p, $1), new_pat_var(p, $1));
}
| symbol tASSOC p_as
{
/* {:"key" => pattern} or {:key => pattern} */
$$ = cons($1, $3);
}
;
/* Keyword rest pattern: **var, **nil, or ** */
File diff suppressed because it is too large Load Diff