mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Correctly handle empty hash as default named argument
```
def func(arg: {})
p arg
end
```
This used to work in earlier mruby versions, but broke somewhere recently.
This commit is contained in:
@@ -4563,13 +4563,13 @@ f_label : tIDENTIFIER tLABEL_TAG
|
||||
{
|
||||
$$ = $1;
|
||||
local_nest(p);
|
||||
p->lstate = EXPR_ARG; /* make newlines significant after label */
|
||||
p->lstate = EXPR_MID; /* make newlines significant after label */
|
||||
}
|
||||
| tNUMPARAM tLABEL_TAG
|
||||
{
|
||||
$$ = intern_numparam($1);
|
||||
local_nest(p);
|
||||
p->lstate = EXPR_ARG; /* make newlines significant after label */
|
||||
p->lstate = EXPR_MID; /* make newlines significant after label */
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
+1167
-1169
File diff suppressed because it is too large
Load Diff
@@ -680,6 +680,20 @@ assert 'keyword arguments' do
|
||||
assert_equal [{a: 1}, {b: 2}], m({a: 1}, b: 2)
|
||||
assert_raise(ArgumentError) { m({a: 1}, {b: 2}) }
|
||||
|
||||
def m1(a: {}) a end
|
||||
assert_equal({}, m1)
|
||||
assert_equal(:abc, m1(a: :abc))
|
||||
|
||||
def m2(a: +1) a end
|
||||
assert_equal(1, m2)
|
||||
|
||||
assert_nothing_raised do
|
||||
def m3 arg:
|
||||
123
|
||||
end
|
||||
end
|
||||
assert_equal(123, m3(arg: 456))
|
||||
|
||||
def m(*, a:) a end
|
||||
assert_equal 1, m(a: 1)
|
||||
assert_equal 3, m(1, 2, a: 3)
|
||||
|
||||
Reference in New Issue
Block a user