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

This commit is contained in:
Nobuyoshi Nakada 2022-03-18 00:35:02 +09:00
Родитель e660b934b9
Коммит 4fdb10e65e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7CD2805BFA3770C6
2 изменённых файлов: 6 добавлений и 4 удалений

9
eval.c
Просмотреть файл

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

Просмотреть файл

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