1
0
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:
yuyi 2023-02-05 15:13:19 +08:00 committed by GitHub
parent d349648cda
commit c40e25b028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 28 deletions

View File

@ -162,6 +162,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
}
// TODO: no buffer fiddling
ast.AnonFn {
if !(var_type.has_flag(.option) || var_type.has_flag(.result)) {
if blank_assign {
g.write('{')
}
@ -193,6 +194,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
}
continue
}
}
else {}
}
unwrapped_val_type := g.unwrap_generic(val_type)

View 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'
}
}