diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-10-01 16:18:03 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-10-01 16:24:36 +0900 |
commit | 56f2fd3bc9bbc69abe75def25f89dac41eb19773 (patch) | |
tree | 628224ab30747d3628485b05c74ebd20a4e6e200 | |
parent | 15d3b7fe6dd421cc4ff77d106d17b0e9fd1ead45 (diff) | |
download | ruby-56f2fd3bc9bbc69abe75def25f89dac41eb19773.tar.gz |
Use the dedicated function to check arity
-rw-r--r-- | struct.c | 4 | ||||
-rw-r--r-- | vm_insnhelper.c | 9 |
2 files changed, 7 insertions, 6 deletions
@@ -742,7 +742,7 @@ rb_struct_initialize_m(int argc, const VALUE *argv, VALUE self) switch (rb_struct_s_keyword_init(klass)) { default: if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) { - rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc); + rb_error_arity(argc, 0, 0); } keyword_init = true; break; @@ -1800,7 +1800,7 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self) return Qnil; } if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) { - rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc); + rb_error_arity(argc, 0, 0); } if (RHASH_SIZE(argv[0]) < num_members) { diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 98138f5922..03796d2ad1 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -428,16 +428,17 @@ rb_vm_pop_frame(rb_execution_context_t *ec) static inline VALUE rb_arity_error_new(int argc, int min, int max) { - VALUE err_mess = 0; + VALUE err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d", argc, min); if (min == max) { - err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d)", argc, min); + /* max is not needed */ } else if (max == UNLIMITED_ARGUMENTS) { - err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d+)", argc, min); + rb_str_cat_cstr(err_mess, "+"); } else { - err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d..%d)", argc, min, max); + rb_str_catf(err_mess, "..%d", max); } + rb_str_cat_cstr(err_mess, ")"); return rb_exc_new3(rb_eArgError, err_mess); } |