diff --git a/ChangeLog b/ChangeLog index 6c908f8d332f30..d421589c8f7423 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,16 @@ +Mon Dec 26 22:38:35 2011 Yusuke Endoh + + * vm_insnhelper.c (unknown_keyword_error): make it kind a error + message when unknown keyword is given. It require more work. + See [ruby-core:40518] and [ruby-core:40541] in detail. + Mon Dec 26 22:31:07 2011 Yusuke Endoh * vm_core.h (struct rb_iseq_struct), compile.c (iseq_set_arguments), iseq.c (rb_iseq_parameters), vm_insnhelper.c (vm_callee_setup_arg_complex): support Method#parameters for keyword arguments. The provisional spec is what Benoit Daloze proposed. - [ruby-core:40518] + [ruby-core:40541] * test/ruby/test_keyword.rb: add a test for above. diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 5ab1eac1ead960..1fdf330632d19f 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -136,9 +136,17 @@ NORETURN(static void unknown_keyword_error(const rb_iseq_t *iseq, VALUE hash)); static void unknown_keyword_error(const rb_iseq_t *iseq, VALUE hash) { - (void) iseq; - (void) hash; - rb_raise(rb_eArgError, "unknown keyword"); + VALUE sep = rb_usascii_str_new2(", "), keys; + const char *msg; + int i; + for (i = 0; i < iseq->arg_keywords; i++) { + rb_hash_delete(hash, ID2SYM(iseq->arg_keyword_table[i])); + } + keys = rb_funcall(hash, rb_intern("keys"), 0, 0); + if (TYPE(keys) != T_ARRAY) rb_raise(rb_eArgError, "unknown keyword"); + msg = RARRAY_LEN(keys) == 1 ? "unknown keyword: %s" : "unknown keywords: %s"; + keys = rb_funcall(keys, rb_intern("join"), 1, sep); + rb_raise(rb_eArgError, msg, RSTRING_PTR(keys)); } #define VM_CALLEE_SETUP_ARG(ret, th, iseq, orig_argc, orig_argv, block) \