diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-27 10:15:47 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-27 10:15:47 +0000 |
commit | 6115f65d7dd29561710c3e84bb27180e5bab4380 (patch) | |
tree | 637d955e548699811e54d3044b9bdfa4113a3ba2 /class.c | |
parent | 955c7f0698d2229f72ae9b9d2a49a1cbecb606e9 (diff) |
* vm_args.c: fix backtrace location for keyword related exceptions.
For example, the following program
def foo(k1: 1); end # line 1
foo(k2: 2) # line 2
causes "unknown keyword: k2 (ArgumentError)".
Before this patch, the backtrace location is only line 2.
However, error should be located at line 1 (over line 2 in
stack trace). This patch fix this problem.
* class.c (rb_keyword_error_new): separate exception creation logic
from rb_keyword_error(), to use in vm_args.c.
* vm_insnhelper.c (rb_arg_error_new): rename to rb_arity_error_new().
* vm_args.c (argument_arity_error): rename to argument_arity_error().
* vm_args.c (arugment_kw_error): added to fix backtrace.
* test/ruby/test_keyword.rb: add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r-- | class.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -1857,11 +1857,12 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...) return argc; } -NORETURN(void rb_keyword_error(const char *error, VALUE keys)); -void -rb_keyword_error(const char *error, VALUE keys) +VALUE +rb_keyword_error_new(const char *error, VALUE keys) { const char *msg = ""; + VALUE error_message; + if (RARRAY_LEN(keys) == 1) { keys = RARRAY_AREF(keys, 0); } @@ -1869,7 +1870,17 @@ rb_keyword_error(const char *error, VALUE keys) keys = rb_ary_join(keys, rb_usascii_str_new2(", ")); msg = "s"; } - rb_raise(rb_eArgError, "%s keyword%s: %"PRIsVALUE, error, msg, keys); + + error_message = rb_sprintf("%s keyword%s: %"PRIsVALUE, error, msg, keys); + + return rb_exc_new_str(rb_eArgError, error_message); +} + +NORETURN(static void rb_keyword_error(const char *error, VALUE keys)); +static void +rb_keyword_error(const char *error, VALUE keys) +{ + rb_exc_raise(rb_keyword_error_new(error, keys)); } NORETURN(static void unknown_keyword_error(VALUE hash, const ID *table, int keywords)); |