diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-01-12 23:14:35 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-01-12 23:14:35 +0900 |
| commit | 8d61f2120c7b3c637ce61df4c13e4b066029a4d5 (patch) | |
| tree | 90ef343888ae25ec72659b79467946acd4186fa2 /src/vm.c | |
| parent | a3571240e5fdbdac9210be27e2445e3f82239f44 (diff) | |
| download | mruby-8d61f2120c7b3c637ce61df4c13e4b066029a4d5.tar.gz mruby-8d61f2120c7b3c637ce61df4c13e4b066029a4d5.zip | |
Add proper given argument number in the wrong-number-argument error.
Diffstat (limited to 'src/vm.c')
| -rw-r--r-- | src/vm.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -717,15 +717,22 @@ argnum_error(mrb_state *mrb, mrb_int num) { mrb_value exc; mrb_value str; + mrb_int argc = mrb->c->ci->argc; + if (argc < 0) { + mrb_value args = mrb->c->stack[1]; + if (mrb_array_p(args)) { + argc = RARRAY_LEN(args); + } + } if (mrb->c->ci->mid) { str = mrb_format(mrb, "'%S': wrong number of arguments (%S for %S)", mrb_sym2str(mrb, mrb->c->ci->mid), - mrb_fixnum_value(mrb->c->ci->argc), mrb_fixnum_value(num)); + mrb_fixnum_value(argc), mrb_fixnum_value(num)); } else { str = mrb_format(mrb, "wrong number of arguments (%S for %S)", - mrb_fixnum_value(mrb->c->ci->argc), mrb_fixnum_value(num)); + mrb_fixnum_value(argc), mrb_fixnum_value(num)); } exc = mrb_exc_new_str(mrb, E_ARGUMENT_ERROR, str); mrb_exc_set(mrb, exc); |
