ruby-changes:56129
From: Nobuyoshi <ko1@a...>
Date: Mon, 17 Jun 2019 22:36:16 +0900 (JST)
Subject: [ruby-changes:56129] Nobuyoshi Nakada: c8e9e0b74b (trunk): Fix wrong "void value expression" error
https://git.ruby-lang.org/ruby.git/commit/?id=c8e9e0b74b From c8e9e0b74b7fb2e225af8708426389db88f80683 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 17 Jun 2019 22:30:52 +0900 Subject: Fix wrong "void value expression" error * parse.y (value_expr_check): `then` or `else` only `if` is not a void value expression, as the counterpart is evaluated as `nil`. [Bug #15932] diff --git a/parse.y b/parse.y index eb00b7c..b966a0a 100644 --- a/parse.y +++ b/parse.y @@ -10552,12 +10552,10 @@ value_expr_check(struct parser_params *p, NODE *node) https://github.com/ruby/ruby/blob/trunk/parse.y#L10552 case NODE_IF: case NODE_UNLESS: if (!node->nd_body) { - node = node->nd_else; - break; + return NULL; } else if (!node->nd_else) { - node = node->nd_body; - break; + return NULL; } vn = value_expr_check(p, node->nd_body); if (!vn) return NULL; diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 541170f..7d99c23 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1392,6 +1392,8 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1392 mesg = /void value expression/ assert_syntax_error("tap {a = (true ? next : break)}", mesg) assert_valid_syntax("tap {a = (true ? true : break)}") + assert_valid_syntax("tap {a = (break if false)}") + assert_valid_syntax("tap {a = (break unless true)}") end private -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/