mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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 ** */
|
||||
|
||||
+3404
-3515
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user