mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix assigning option of struct fntype field (#17224)
This commit is contained in:
parent
d349648cda
commit
c40e25b028
@ -162,6 +162,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
|
|||||||
}
|
}
|
||||||
// TODO: no buffer fiddling
|
// TODO: no buffer fiddling
|
||||||
ast.AnonFn {
|
ast.AnonFn {
|
||||||
|
if !(var_type.has_flag(.option) || var_type.has_flag(.result)) {
|
||||||
if blank_assign {
|
if blank_assign {
|
||||||
g.write('{')
|
g.write('{')
|
||||||
}
|
}
|
||||||
@ -193,6 +194,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
unwrapped_val_type := g.unwrap_generic(val_type)
|
unwrapped_val_type := g.unwrap_generic(val_type)
|
||||||
|
16
vlib/v/tests/assign_option_of_struct_fntype_field_test.v
Normal file
16
vlib/v/tests/assign_option_of_struct_fntype_field_test.v
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
struct Foo {
|
||||||
|
mut:
|
||||||
|
bar ?fn (string) string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_assign_option_of_struct_fntype_field() {
|
||||||
|
mut foo := Foo{}
|
||||||
|
foo.bar = fn (s string) string {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
if ff := foo.bar {
|
||||||
|
ret := ff('hello')
|
||||||
|
println(ret)
|
||||||
|
assert ret == 'hello'
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user