Skip to content


Fix parameters when noname rest
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Apr 2, 2017
1 parent 5d00e85 commit be5c304
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mrbgems/mruby-proc-ext/src/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,16 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
parameters_list[4].size = MRB_ASPEC_BLOCK(aspec);

parameters = mrb_ary_new_capa(mrb, irep->nlocals-1);

for (i = 0, p = parameters_list; p->name; p++) {
mrb_value sname = mrb_symbol_value(mrb_intern_cstr(mrb, p->name));
for (j = 0; j < p->size; i++, j++) {
mrb_assert(i < (irep->nlocals-1));
mrb_ary_push(mrb, parameters, mrb_assoc_new(mrb,
mrb_value a = mrb_ary_new(mrb);
mrb_ary_push(mrb, a, sname);
if (irep->lv[i].name) {
mrb_ary_push(mrb, a, mrb_symbol_value(irep->lv[i].name));
mrb_ary_push(mrb, parameters, a);
return parameters;
Expand Down
1 change: 1 addition & 0 deletions mrbgems/mruby-proc-ext/test/proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
assert_equal([[:req, :a]], lambda {|a|}.parameters)
assert_equal([[:opt, :a]], lambda {|a=nil|}.parameters)
assert_equal([[:req, :a]], ->(a){}.parameters)
assert_equal([[:rest]], lambda { |*| }.parameters)
assert_equal([[:rest, :a]], {|*a|}.parameters)
assert_equal([[:opt, :a], [:opt, :b], [:opt, :c], [:opt, :d], [:rest, :e], [:opt, :f], [:opt, :g], [:block, :h]], {|a,b,c=:c,d=:d,*e,f,g,&h|}.parameters)
assert_equal([[:req, :a], [:req, :b], [:opt, :c], [:opt, :d], [:rest, :e], [:req, :f], [:req, :g], [:block, :h]], lambda {|a,b,c=:c,d=:d,*e,f,g,&h|}.parameters)
Expand Down

0 comments on commit be5c304

Please sign in to comment.