mirror of
https://github.com/vlang/v.git
synced 2025-09-12 17:07:11 -04:00
parent
d977154b21
commit
f72f1fc893
@ -1048,7 +1048,7 @@ fn (mut g Gen) infix_expr_and_or_op(node ast.InfixExpr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (mut g Gen) gen_is_none_check(node ast.InfixExpr) {
|
fn (mut g Gen) gen_is_none_check(node ast.InfixExpr) {
|
||||||
if node.left in [ast.Ident, ast.SelectorExpr, ast.IndexExpr] {
|
if node.left in [ast.Ident, ast.SelectorExpr, ast.IndexExpr, ast.CallExpr] {
|
||||||
old_inside_opt_or_res := g.inside_opt_or_res
|
old_inside_opt_or_res := g.inside_opt_or_res
|
||||||
g.inside_opt_or_res = true
|
g.inside_opt_or_res = true
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
|
28
vlib/v/tests/method_call_none_check_test.v
Normal file
28
vlib/v/tests/method_call_none_check_test.v
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
struct Foo {
|
||||||
|
x int
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
x int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Foobar = Bar | Foo
|
||||||
|
|
||||||
|
struct Foobars {
|
||||||
|
m map[string]Foobar
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (f &Foobars) find_foobar(name string) ?Foobar {
|
||||||
|
return f.m[name] or { return none }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut f Foobars) is_known(name string) bool {
|
||||||
|
return f.find_foobar(name) != none
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
mut foobars := Foobars{
|
||||||
|
m: map[string]Foobar{}
|
||||||
|
}
|
||||||
|
assert foobars.is_known('deadbeef') == false
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user