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

ruby-changes:68300

From: Nobuyoshi <ko1@a...>
Date: Fri, 8 Oct 2021 00:15:38 +0900 (JST)
Subject: [ruby-changes:68300] 8057129da6 (master): Remove duplicate value checks on `mrhs` which always has the value

https://git.ruby-lang.org/ruby.git/commit/?id=8057129da6

From 8057129da61e7fc920b0cd1cb09105125819c10f Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 8 Oct 2021 00:10:32 +0900
Subject: Remove duplicate value checks on `mrhs` which always has the value

---
 parse.y                 | 5 +++--
 test/ruby/test_parse.rb | 8 +++++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/parse.y b/parse.y
index 3ae456ca4c..bf0d33a491 100644
--- a/parse.y
+++ b/parse.y
@@ -1586,7 +1586,6 @@ stmt		: keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1586
 		| lhs '=' lex_ctxt mrhs
 		    {
 		    /*%%%*/
-			value_expr($4);
 			$$ = node_assign(p, $1, $4, $3, &@$);
 		    /*% %*/
 		    /*% ripper: assign!($1, $4) %*/
@@ -1595,7 +1594,6 @@ stmt		: keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1594
                     {
                     /*%%%*/
                         YYLTYPE loc = code_loc_gen(&@5, &@6);
-                        value_expr($4);
 			$$ = node_assign(p, $1, NEW_RESCUE($4, NEW_RESBODY(0, remove_begin($6), 0, &loc), 0, &@$), $3, &@$);
                     /*% %*/
                     /*% ripper: massign!($1, rescue_mod!($4, $6)) %*/
@@ -2861,6 +2859,7 @@ opt_block_arg	: ',' block_arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2859
 		    }
 		;
 
+/* value */
 args		: arg_value
 		    {
 		    /*%%%*/
@@ -2891,10 +2890,12 @@ args		: arg_value https://github.com/ruby/ruby/blob/trunk/parse.y#L2890
 		    }
 		;
 
+/* value */
 mrhs_arg	: mrhs
 		| arg_value
 		;
 
+/* value */
 mrhs		: args ',' arg_value
 		    {
 		    /*%%%*/
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index a9e8417357..3120016e60 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1231,10 +1231,12 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1231
     assert_valid_syntax('let () { m(a) do; end }')
   end
 
-  def test_void_value_in_command_rhs
+  def test_void_value_in_rhs
     w = "void value expression"
-    ex = assert_syntax_error("x = return 1", w)
-    assert_equal(1, ex.message.scan(w).size, "same #{w.inspect} warning should be just once")
+    ["x = return 1", "x = return, 1", "x = 1, return", "x, y = return"].each do |code|
+      ex = assert_syntax_error(code, w)
+      assert_equal(1, ex.message.scan(w).size, ->{"same #{w.inspect} warning should be just once\n#{w.message}"})
+    end
   end
 
   def eval_separately(code)
-- 
cgit v1.2.1


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

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