1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix if guard with struct option fntype field (#17220)

This commit is contained in:
yuyi 2023-02-04 17:38:07 +08:00 committed by GitHub
parent 804065a0fa
commit e8ca2e62a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -800,7 +800,11 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
typ = obj.smartcasts.last()
} else {
if obj.typ == 0 {
typ = c.expr(obj.expr)
if obj.expr is ast.IfGuardExpr {
typ = c.expr(obj.expr.expr)
} else {
typ = c.expr(obj.expr)
}
} else {
typ = obj.typ
}

View File

@ -0,0 +1,19 @@
struct Foo {
f ?fn (int) int
}
fn t1(a int) int {
println(a)
return a
}
fn test_if_guard_with_struct_option_fntype_field() {
foo := Foo{t1}
if ff := foo.f {
ret := ff(22)
assert ret == 22
} else {
assert false
}
}