1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

A positional Hash is not keyword arguments [Bug #18632]

This commit is contained in:
Nobuyoshi Nakada 2022-03-18 00:35:02 +09:00
parent e660b934b9
commit 4fdb10e65e
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
Notes: git 2022-03-18 00:39:17 +09:00
2 changed files with 6 additions and 4 deletions

9
eval.c
View file

@ -695,17 +695,18 @@ rb_interrupt(void)
enum {raise_opt_cause, raise_max_opt}; /*< \private */ enum {raise_opt_cause, raise_max_opt}; /*< \private */
static int static int
extract_raise_opts(int argc, const VALUE *argv, VALUE *opts) extract_raise_opts(int argc, VALUE *argv, VALUE *opts)
{ {
int i; int i;
if (argc > 0) { if (argc > 0) {
VALUE opt = argv[argc-1]; VALUE opt;
if (RB_TYPE_P(opt, T_HASH)) { argc = rb_scan_args(argc, argv, "*:", NULL, &opt);
if (!NIL_P(opt)) {
if (!RHASH_EMPTY_P(opt)) { if (!RHASH_EMPTY_P(opt)) {
ID keywords[1]; ID keywords[1];
CONST_ID(keywords[0], "cause"); CONST_ID(keywords[0], "cause");
rb_get_kwargs(opt, keywords, 0, -1-raise_max_opt, opts); rb_get_kwargs(opt, keywords, 0, -1-raise_max_opt, opts);
if (RHASH_EMPTY_P(opt)) --argc; if (!RHASH_EMPTY_P(opt)) argv[argc++] = opt;
return argc; return argc;
} }
} }

View file

@ -807,6 +807,7 @@ end.join
cause = ArgumentError.new("foobar") cause = ArgumentError.new("foobar")
e = assert_raise(RuntimeError) {raise msg, cause: cause} e = assert_raise(RuntimeError) {raise msg, cause: cause}
assert_same(cause, e.cause) assert_same(cause, e.cause)
assert_raise(TypeError) {raise msg, {cause: cause}}
end end
def test_cause_with_no_arguments def test_cause_with_no_arguments