From 0737af92d53909f4eb21b69b2889faa401a2bada Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Wed, 5 Nov 2025 16:12:05 +0800 Subject: [PATCH] checker: fix or block endwiths expr (fix #25329) (#25667) --- vlib/v/checker/checker.v | 6 +++++- vlib/v/tests/or_block_endwiths_expr_test.v | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/or_block_endwiths_expr_test.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index dbd8791e3..a1da07a0c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2928,7 +2928,11 @@ fn (mut c Checker) stmts_ending_with_expression(mut stmts []ast.Stmt, expected_o unreachable = stmt.pos } prev_expected_or_type := c.expected_or_type - c.expected_or_type = expected_or_type + c.expected_or_type = if c.is_last_stmt { + expected_or_type + } else { + ast.void_type + } c.stmt(mut stmt) c.expected_or_type = prev_expected_or_type if !c.inside_anon_fn && c.in_for_count > 0 && stmt is ast.BranchStmt diff --git a/vlib/v/tests/or_block_endwiths_expr_test.v b/vlib/v/tests/or_block_endwiths_expr_test.v new file mode 100644 index 000000000..c345deb30 --- /dev/null +++ b/vlib/v/tests/or_block_endwiths_expr_test.v @@ -0,0 +1,20 @@ +fn some_fn(text string) string { + mut some_map := map[string]string{} + + key := '' + found := some_map[key] or { + if true { + if true { + } else { + } + } else { + } + + 'no' + } + return found +} + +fn test_or_block_endwiths_expr() { + assert some_fn('abc abc') == 'no' +} -- 2.39.5