Permalink
Browse files

Fix parameters when noname rest

  • Loading branch information...
ksss committed Apr 2, 2017
1 parent 5d00e85 commit be5c304b4cb4dc99748f441210ee9cdbab33551c
Showing with 8 additions and 5 deletions.
  1. +7 −5 mrbgems/mruby-proc-ext/src/proc.c
  2. +1 −0 mrbgems/mruby-proc-ext/test/proc.rb
@@ -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,
sname,
mrb_symbol_value(irep->lv[i].name)
));
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;
@@ -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]], Proc.new {|*a|}.parameters)
assert_equal([[:opt, :a], [:opt, :b], [:opt, :c], [:opt, :d], [:rest, :e], [:opt, :f], [:opt, :g], [:block, :h]], Proc.new {|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)

0 comments on commit be5c304

Please sign in to comment.