mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
74efd2621b
commit
ae816b1719
@ -113,7 +113,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
|
||||
p.check(.decl_assign)
|
||||
comments << p.eat_comments()
|
||||
expr := p.expr(0)
|
||||
if expr !in [ast.CallExpr, ast.IndexExpr, ast.PrefixExpr] {
|
||||
if expr !in [ast.CallExpr, ast.IndexExpr, ast.PrefixExpr, ast.SelectorExpr] {
|
||||
p.error_with_pos('if guard condition expression is illegal, it should return optional',
|
||||
expr.pos())
|
||||
}
|
||||
|
@ -12,11 +12,13 @@
|
||||
[vlib/v/tests/inout/struct_field_optional.vv:33] sum: 4
|
||||
4
|
||||
[vlib/v/tests/inout/struct_field_optional.vv:36] sum: 4
|
||||
3
|
||||
none
|
||||
Foo{
|
||||
bar: 3
|
||||
baz: 0
|
||||
}
|
||||
[vlib/v/tests/inout/struct_field_optional.vv:39] f: Foo{
|
||||
[vlib/v/tests/inout/struct_field_optional.vv:50] f: Foo{
|
||||
bar: 3
|
||||
baz: 0
|
||||
}
|
||||
|
@ -34,6 +34,17 @@ fn main() {
|
||||
sum = f.bar or { 123 } + 1
|
||||
println(sum)
|
||||
dump(sum)
|
||||
// `if guard` test
|
||||
if c := f.bar {
|
||||
println(c)
|
||||
} else {
|
||||
println(err)
|
||||
}
|
||||
if c := f.baz {
|
||||
println(c)
|
||||
} else {
|
||||
println(err)
|
||||
}
|
||||
// others test
|
||||
println(f)
|
||||
dump(f)
|
||||
|
Loading…
Reference in New Issue
Block a user