Skip to content

Commit 0737af9

Browse files
authored
checker: fix or block endwiths expr (fix #25329) (#25667)
1 parent 86d2063 commit 0737af9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

vlib/v/checker/checker.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2928,7 +2928,11 @@ fn (mut c Checker) stmts_ending_with_expression(mut stmts []ast.Stmt, expected_o
29282928
unreachable = stmt.pos
29292929
}
29302930
prev_expected_or_type := c.expected_or_type
2931-
c.expected_or_type = expected_or_type
2931+
c.expected_or_type = if c.is_last_stmt {
2932+
expected_or_type
2933+
} else {
2934+
ast.void_type
2935+
}
29322936
c.stmt(mut stmt)
29332937
c.expected_or_type = prev_expected_or_type
29342938
if !c.inside_anon_fn && c.in_for_count > 0 && stmt is ast.BranchStmt
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fn some_fn(text string) string {
2+
mut some_map := map[string]string{}
3+
4+
key := ''
5+
found := some_map[key] or {
6+
if true {
7+
if true {
8+
} else {
9+
}
10+
} else {
11+
}
12+
13+
'no'
14+
}
15+
return found
16+
}
17+
18+
fn test_or_block_endwiths_expr() {
19+
assert some_fn('abc abc') == 'no'
20+
}

0 commit comments

Comments
 (0)