Skip to content

Commit

Permalink
* vm_insnhelper.c (unknown_keyword_error): make it kind a error messa…
Browse files Browse the repository at this point in the history
…ge when unknown keyword is given. It require more work. See [ruby-core:40518] and [ruby-core:40541] in detail.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
mame committed Dec 26, 2011
1 parent d0baa0d commit c5e372f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
Mon Dec 26 22:38:35 2011 Yusuke Endoh <[email protected]>

* 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 <[email protected]>

* 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.

Expand Down
14 changes: 11 additions & 3 deletions vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down

0 comments on commit c5e372f

Please sign in to comment.