diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-12-05 18:52:34 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-02-04 13:28:33 +0900 |
| commit | c8b2a453d0fe099064e095d165ce38ee8c3eef38 (patch) | |
| tree | 6bd475dde36521ac60058bb49b9a37effdd130d1 | |
| parent | 995c80bcd8509f59374506c04b60d94128cc2699 (diff) | |
[Bug #21669] Fix void value expression check for `rescue`
If any `rescue` node is non-void, the enclosing block is also
non-void.
| -rw-r--r-- | parse.y | 3 | ||||
| -rw-r--r-- | test/ruby/test_syntax.rb | 16 |
2 files changed, 17 insertions, 2 deletions
@@ -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") |
