summaryrefslogtreecommitdiffhomepage
path: root/src/vm.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-01-12 23:14:35 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-01-12 23:14:35 +0900
commit8d61f2120c7b3c637ce61df4c13e4b066029a4d5 (patch)
tree90ef343888ae25ec72659b79467946acd4186fa2 /src/vm.c
parenta3571240e5fdbdac9210be27e2445e3f82239f44 (diff)
downloadmruby-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.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/vm.c b/src/vm.c
index 9cc29ed5a..5d2e04383 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -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);