[前][次][番号順一覧][スレッド一覧]

ruby-changes:71449

From: Nobuyoshi <ko1@a...>
Date: Fri, 18 Mar 2022 00:39:09 +0900 (JST)
Subject: [ruby-changes:71449] 4fdb10e65e (master): A positional Hash is not keyword arguments [Bug #18632]

https://git.ruby-lang.org/ruby.git/commit/?id=4fdb10e65e

From 4fdb10e65e3e32dad99a8a8efecc04bf7c85f024 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 18 Mar 2022 00:35:02 +0900
Subject: A positional Hash is not keyword arguments [Bug #18632]

---
 eval.c                      | 9 +++++----
 test/ruby/test_exception.rb | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/eval.c b/eval.c
index d91440676f..3a1a6b45df 100644
--- a/eval.c
+++ b/eval.c
@@ -695,17 +695,18 @@ rb_interrupt(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L695
 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;
 	    }
 	}
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index ffa7aa6703..0b05ff7c51 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -807,6 +807,7 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L807
     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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]