summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2025-12-05 19:01:21 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2026-02-04 13:28:33 +0900
commit932ce048feb9f26bcd9e8dc93ada4d2a407ace1f (patch)
treefca6fc1a0d75d07f1dc07b2d8aa2037ff89d9f03 /parse.y
parent4f360107387c47bfd82e7010b8eb7393575d4d76 (diff)
[Bug #21669] Implement void value expression check for `case`/`when`
If the all `when` and `else` branches are void, the `case` is also void.
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y12
1 files changed, 12 insertions, 0 deletions
diff --git a/parse.y b/parse.y
index 7efc7a7ea5..63b6ab9b16 100644
--- a/parse.y
+++ b/parse.y
@@ -13864,6 +13864,18 @@ value_expr_check(struct parser_params *p, NODE *node)
case NODE_RETRY:
goto found;
+ case NODE_CASE:
+ case NODE_CASE2:
+ for (node = RNODE_CASE(node)->nd_body;
+ node && nd_type_p(node, NODE_WHEN);
+ node = RNODE_WHEN(node)->nd_next) {
+ if (!(vn = value_expr_check(p, RNODE_WHEN(node)->nd_body))) {
+ return NULL;
+ }
+ if (!void_node) void_node = vn;
+ }
+ break;
+
case NODE_CASE3:
if (!RNODE_CASE3(node)->nd_body || !nd_type_p(RNODE_CASE3(node)->nd_body, NODE_IN)) {
compile_error(p, "unexpected node");