diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2021-02-28 15:04:13 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2021-02-28 15:04:13 +0000 |
commit | f279c3a37602f57426d144d32c464caf1bd05227 (patch) | |
tree | f5853eb2e8b21e69050d56473f0746ad8648de03 | |
parent | 4be089c0dd720324730230c1abfe0c200d125359 (diff) |
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
-rw-r--r-- | parse.y | 33 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 6 | ||||
-rw-r--r-- | version.h | 8 |
3 files changed, 32 insertions, 15 deletions
@@ -9478,10 +9478,10 @@ node_assign(struct parser_params *p, NODE *lhs, NODE *rhs, const YYLTYPE *loc) 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) 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) 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) 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 4e403a9ffd..3e77f44efe 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1306,6 +1306,12 @@ eom 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 @@ -1,10 +1,10 @@ #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" |