Skip to content

Commit f72f1fc

Browse files
authored
cgen: fix method call checking against none (fix #20711) (#20717)
1 parent d977154 commit f72f1fc

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

vlib/v/gen/c/infix.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ fn (mut g Gen) infix_expr_and_or_op(node ast.InfixExpr) {
10481048
}
10491049

10501050
fn (mut g Gen) gen_is_none_check(node ast.InfixExpr) {
1051-
if node.left in [ast.Ident, ast.SelectorExpr, ast.IndexExpr] {
1051+
if node.left in [ast.Ident, ast.SelectorExpr, ast.IndexExpr, ast.CallExpr] {
10521052
old_inside_opt_or_res := g.inside_opt_or_res
10531053
g.inside_opt_or_res = true
10541054
g.expr(node.left)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
struct Foo {
2+
x int
3+
}
4+
5+
struct Bar {
6+
x int
7+
}
8+
9+
type Foobar = Bar | Foo
10+
11+
struct Foobars {
12+
m map[string]Foobar
13+
}
14+
15+
fn (f &Foobars) find_foobar(name string) ?Foobar {
16+
return f.m[name] or { return none }
17+
}
18+
19+
fn (mut f Foobars) is_known(name string) bool {
20+
return f.find_foobar(name) != none
21+
}
22+
23+
fn test_main() {
24+
mut foobars := Foobars{
25+
m: map[string]Foobar{}
26+
}
27+
assert foobars.is_known('deadbeef') == false
28+
}

0 commit comments

Comments
 (0)