Skip to content

Commit 1e71fa3

Browse files
authored
checker: fix missing type bounding to match expr on or{} expr (fix #24656) (#24658)
1 parent a13821a commit 1e71fa3

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎vlib/v/checker/checker.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,7 @@ fn (mut c Checker) check_or_last_stmt(mut stmt ast.Stmt, ret_type ast.Type, expr
14871487
return
14881488
}
14891489
last_stmt_typ := c.expr(mut stmt.expr)
1490+
stmt.typ = last_stmt_typ
14901491
if last_stmt_typ.has_flag(.option) || last_stmt_typ == ast.none_type {
14911492
if stmt.expr in [ast.Ident, ast.SelectorExpr, ast.CallExpr, ast.None, ast.CastExpr] {
14921493
expected_type_name := c.table.type_to_str(ret_type.clear_option_and_result())

‎vlib/v/tests/match_or_expr_test.v‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct Foo {
2+
option ?int = none
3+
}
4+
5+
fn test_main() {
6+
test := true
7+
foo := Foo{}
8+
result := foo.option or {
9+
match test {
10+
true { 1 }
11+
else { 2 }
12+
}
13+
}
14+
15+
assert result == 1
16+
}

0 commit comments

Comments
 (0)