mirror of
https://github.com/vlang/v.git
synced 2025-09-13 06:22:26 +03:00
This commit is contained in:
parent
a13821a951
commit
1e71fa3e38
2 changed files with 17 additions and 0 deletions
|
@ -1487,6 +1487,7 @@ fn (mut c Checker) check_or_last_stmt(mut stmt ast.Stmt, ret_type ast.Type, expr
|
|||
return
|
||||
}
|
||||
last_stmt_typ := c.expr(mut stmt.expr)
|
||||
stmt.typ = last_stmt_typ
|
||||
if last_stmt_typ.has_flag(.option) || last_stmt_typ == ast.none_type {
|
||||
if stmt.expr in [ast.Ident, ast.SelectorExpr, ast.CallExpr, ast.None, ast.CastExpr] {
|
||||
expected_type_name := c.table.type_to_str(ret_type.clear_option_and_result())
|
||||
|
|
16
vlib/v/tests/match_or_expr_test.v
Normal file
16
vlib/v/tests/match_or_expr_test.v
Normal file
|
@ -0,0 +1,16 @@
|
|||
struct Foo {
|
||||
option ?int = none
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
test := true
|
||||
foo := Foo{}
|
||||
result := foo.option or {
|
||||
match test {
|
||||
true { 1 }
|
||||
else { 2 }
|
||||
}
|
||||
}
|
||||
|
||||
assert result == 1
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue