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:
parent
804065a0fa
commit
e8ca2e62a7
@ -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 {
|
||||
if obj.expr is ast.IfGuardExpr {
|
||||
typ = c.expr(obj.expr.expr)
|
||||
} else {
|
||||
typ = c.expr(obj.expr)
|
||||
}
|
||||
} else {
|
||||
typ = obj.typ
|
||||
}
|
||||
|
19
vlib/v/tests/if_guard_with_struct_option_fntype_field_test.v
Normal file
19
vlib/v/tests/if_guard_with_struct_option_fntype_field_test.v
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user