From c8b2a453d0fe099064e095d165ce38ee8c3eef38 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 5 Dec 2025 18:52:34 +0900 Subject: [Bug #21669] Fix void value expression check for `rescue` If any `rescue` node is non-void, the enclosing block is also non-void. --- parse.y | 3 +-- test/ruby/test_syntax.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index 7ca1197b37..b20141680e 100644 --- a/parse.y +++ b/parse.y @@ -13847,8 +13847,7 @@ value_expr_check(struct parser_params *p, NODE *node) return NULL; } if (!(vn = value_expr_check(p, RNODE_RESBODY(r)->nd_body))) { - void_node = 0; - break; + return NULL; } if (!void_node) void_node = vn; } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 5065a1db33..79e373ea66 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -2013,6 +2013,8 @@ eom assert_equal(1, b.new.foo(1), bug21256) end + BUG_21669 = '[Bug #21669]' + def test_value_expr_in_condition mesg = /void value expression/ assert_syntax_error("tap {a = (true ? next : break)}", mesg) @@ -2026,6 +2028,20 @@ eom assert_syntax_error("class << (return); end", mesg) end + def test_value_expr_in_rescue + assert_valid_syntax("#{<<~"{#"}\n#{<<~'};'}", "#{BUG_21669} 1.1") + {# + x = begin + raise + return + rescue + "OK" + else + return + end + }; + end + def test_tautological_condition assert_valid_syntax("def f() return if false and invalid; nil end") assert_valid_syntax("def f() return unless true or invalid; nil end") -- cgit v1.2.3