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

ruby-changes:59915

From: Seiei <ko1@a...>
Date: Mon, 3 Feb 2020 17:55:00 +0900 (JST)
Subject: [ruby-changes:59915] 11963da9e8 (master): Check type of empty keyword [Bug #16603]

https://git.ruby-lang.org/ruby.git/commit/?id=11963da9e8

From 11963da9e8e98821860fbb0c0f2adc118860c814 Mon Sep 17 00:00:00 2001
From: Seiei Miyagi <hanachin@g...>
Date: Mon, 3 Feb 2020 17:43:03 +0900
Subject: Check type of empty keyword [Bug #16603]

Co-authored-by: Yusuke Endoh <mame@r...>

diff --git a/compile.c b/compile.c
index eb36f57..9de9114 100644
--- a/compile.c
+++ b/compile.c
@@ -4253,7 +4253,7 @@ compile_hash(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int popp https://github.com/ruby/ruby/blob/trunk/compile.c#L4253
                 FLUSH_CHUNK();
 
                 const NODE *kw = node->nd_next->nd_head;
-                int empty_kw = nd_type(kw) == NODE_LIT;       /* foo(  ..., **{}, ...) */
+                int empty_kw = nd_type(kw) == NODE_LIT && RB_TYPE_P(kw->nd_lit, T_HASH); /* foo(  ..., **{}, ...) */
                 int first_kw = first_chunk && stack_len == 0; /* foo(1,2,3, **kw, ...) */
                 int last_kw = !node->nd_next->nd_next;        /* foo(  ..., **kw) */
                 int only_kw = last_kw && first_kw;            /* foo(1,2,3, **kw) */
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index 75991ca..db7d696 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -4076,4 +4076,10 @@ class TestKeywordArgumentsSymProcRefinements < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L4076
       mock.new.foo
     end
   end
+
+  def test_splat_fixnum
+    bug16603 = '[ruby-core:97047] [Bug #16603]'
+    assert_raise(TypeError, bug16603) { p(**42) }
+    assert_raise(TypeError, bug16603) { p(k:1, **42) }
+  end
 end
-- 
cgit v0.10.2


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

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