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