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

ruby-changes:65368

From: usa <ko1@a...>
Date: Mon, 1 Mar 2021 00:04:30 +0900 (JST)
Subject: [ruby-changes:65368] f279c3a376 (ruby_2_6): merge revision(s) 01b3a380: [Backport #11143][Backport #15932]

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

From f279c3a37602f57426d144d32c464caf1bd05227 Mon Sep 17 00:00:00 2001
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sun, 28 Feb 2021 15:04:13 +0000
Subject: merge revision(s) 01b3a380: [Backport #11143][Backport #15932]

	Fix wrong "void value expression" error

	* parse.y (value_expr_check): if either of then or else statements is not a void value expression, the whole if is not also a void value expression. [Bug #15932]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 parse.y                  | 33 ++++++++++++++++++++++-----------
 test/ruby/test_syntax.rb |  6 ++++++
 version.h                |  8 ++++----
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/parse.y b/parse.y
index 16bde4d..bf73fb1 100644
--- a/parse.y
+++ b/parse.y
@@ -9478,10 +9478,10 @@ node_assign(struct parser_params *p, NODE *lhs, NODE *rhs, const YYLTYPE *loc) https://github.com/ruby/ruby/blob/trunk/parse.y#L9478
     return lhs;
 }
 
-static int
-value_expr_gen(struct parser_params *p, NODE *node)
+static NODE *
+value_expr_check(struct parser_params *p, NODE *node)
 {
-    int cond = 0;
+    NODE *void_node = 0, *vn;
 
     if (!node) {
 	rb_warning0("empty expression");
@@ -9493,9 +9493,7 @@ value_expr_gen(struct parser_params *p, NODE *node) https://github.com/ruby/ruby/blob/trunk/parse.y#L9493
 	  case NODE_NEXT:
 	  case NODE_REDO:
 	  case NODE_RETRY:
-	    if (!cond) yyerror1(&node->nd_loc, "void value expression");
-	    /* or "control never reach"? */
-	    return FALSE;
+	    return void_node ? void_node : node;
 
 	  case NODE_BLOCK:
 	    while (node->nd_next) {
@@ -9518,14 +9516,15 @@ value_expr_gen(struct parser_params *p, NODE *node) https://github.com/ruby/ruby/blob/trunk/parse.y#L9516
 		node = node->nd_body;
 		break;
 	    }
-	    if (!value_expr(node->nd_body)) return FALSE;
+	    vn = value_expr_check(p, node->nd_body);
+	    if (!vn) return NULL;
+	    if (!void_node) void_node = vn;
 	    node = node->nd_else;
 	    break;
 
 	  case NODE_AND:
 	  case NODE_OR:
-	    cond = 1;
-	    node = node->nd_2nd;
+	    node = node->nd_1st;
 	    break;
 
 	  case NODE_LASGN:
@@ -9533,13 +9532,25 @@ value_expr_gen(struct parser_params *p, NODE *node) https://github.com/ruby/ruby/blob/trunk/parse.y#L9532
 	  case NODE_DASGN_CURR:
 	  case NODE_MASGN:
 	    mark_lvar_used(p, node);
-	    return TRUE;
+	    return NULL;
 
 	  default:
-	    return TRUE;
+	    return NULL;
 	}
     }
 
+    return NULL;
+}
+
+static int
+value_expr_gen(struct parser_params *p, NODE *node)
+{
+    NODE *void_node = value_expr_check(p, node);
+    if (void_node) {
+	yyerror1(&void_node->nd_loc, "void value expression");
+	/* or "control never reach"? */
+	return FALSE;
+    }
     return TRUE;
 }
 
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 4e403a9..3e77f44 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1306,6 +1306,12 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1306
     assert_valid_syntax('obj::foo (1) {}')
   end
 
+  def test_value_expr_in_condition
+    mesg = /void value expression/
+    assert_syntax_error("tap {a = (true ? next : break)}", mesg)
+    assert_valid_syntax("tap {a = (true ? true : break)}")
+  end
+
   private
 
   def not_label(x) @result = x; @not_label ||= nil end
diff --git a/version.h b/version.h
index 792d353..2c86d53 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.7"
-#define RUBY_RELEASE_DATE "2021-02-28"
-#define RUBY_PATCHLEVEL 162
+#define RUBY_RELEASE_DATE "2021-03-01"
+#define RUBY_PATCHLEVEL 163
 
 #define RUBY_RELEASE_YEAR 2021
-#define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 28
+#define RUBY_RELEASE_MONTH 3
+#define RUBY_RELEASE_DAY 1
 
 #include "ruby/version.h"
 
-- 
cgit v1.1


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

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