diff options
Diffstat (limited to 'mrbgems/mruby-proc-ext')
| -rw-r--r-- | mrbgems/mruby-proc-ext/src/proc.c | 12 | ||||
| -rw-r--r-- | mrbgems/mruby-proc-ext/test/proc.rb | 1 |
2 files changed, 8 insertions, 5 deletions
diff --git a/mrbgems/mruby-proc-ext/src/proc.c b/mrbgems/mruby-proc-ext/src/proc.c index 8c9e300dc..0322afe67 100644 --- a/mrbgems/mruby-proc-ext/src/proc.c +++ b/mrbgems/mruby-proc-ext/src/proc.c @@ -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; diff --git a/mrbgems/mruby-proc-ext/test/proc.rb b/mrbgems/mruby-proc-ext/test/proc.rb index 75e11dd93..424c0bc1d 100644 --- a/mrbgems/mruby-proc-ext/test/proc.rb +++ b/mrbgems/mruby-proc-ext/test/proc.rb @@ -53,6 +53,7 @@ assert('Proc#parameters') do 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) |
