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

ruby-changes:67947

From: Shugo <ko1@a...>
Date: Sat, 11 Sep 2021 22:05:42 +0900 (JST)
Subject: [ruby-changes:67947] 7686776c05 (master): Hash values should be omitted in Ripper results

https://git.ruby-lang.org/ruby.git/commit/?id=7686776c05

From 7686776c0563eeb269c5ffa1fc2cf42d4d31e222 Mon Sep 17 00:00:00 2001
From: Shugo Maeda <shugo@r...>
Date: Sat, 11 Sep 2021 22:03:10 +0900
Subject: Hash values should be omitted in Ripper results

---
 parse.y                  |  2 +-
 test/ripper/test_sexp.rb | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/parse.y b/parse.y
index d4443d5..88ae901 100644
--- a/parse.y
+++ b/parse.y
@@ -5624,7 +5624,7 @@ assoc		: arg_value tASSOC arg_value https://github.com/ruby/ruby/blob/trunk/parse.y#L5624
 			if (!val) val = NEW_BEGIN(0, &@$);
 			$$ = list_append(p, NEW_LIST(NEW_LIT(ID2SYM($1), &@1), &@$), val);
 		    /*% %*/
-		    /*% ripper: assoc_new!($1, id_is_var(p, get_id($1)) ? var_ref!($1) : vcall!($1)) %*/
+		    /*% ripper: assoc_new!($1, Qnil) %*/
 		    }
 		| tSTRING_BEG string_contents tLABEL_END arg_value
 		    {
diff --git a/test/ripper/test_sexp.rb b/test/ripper/test_sexp.rb
index b4e70fa..9faeaba 100644
--- a/test/ripper/test_sexp.rb
+++ b/test/ripper/test_sexp.rb
@@ -520,4 +520,18 @@ eot https://github.com/ruby/ruby/blob/trunk/test/ripper/test_sexp.rb#L520
     assert_raise(SyntaxError) { Ripper.sexp('def req(true) end', raise_errors: true) }
     assert_raise(SyntaxError) { Ripper.sexp_raw('def req(true) end', raise_errors: true) }
   end
+
+  def test_hash_value_omission
+    sexp = Ripper.sexp("{x: 1, y:}")
+    assoclist = search_sexp(:assoclist_from_args, sexp)
+    x = assoclist[1][0]
+    assert_equal(:@label, x[1][0])
+    assert_equal("x:", x[1][1])
+    assert_equal(:@int, x[2][0])
+    assert_equal("1", x[2][1])
+    y = assoclist[1][1]
+    assert_equal(:@label, y[1][0])
+    assert_equal("y:", y[1][1])
+    assert_equal(nil, y[2])
+  end
 end if ripper_test
-- 
cgit v1.1


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

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