mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix auto_str for fn type (#17988)
This commit is contained in:
parent
d48aa15514
commit
59d91e0514
@ -190,6 +190,8 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string)
|
||||
g.auto_str_funcs.writeln('\t\tres = ${str_intp_sq(tmp_res)};')
|
||||
} else if should_use_indent_func(sym.kind) && !sym_has_str_method {
|
||||
g.auto_str_funcs.writeln('\t\tres = indent_${parent_str_fn_name}(*(${sym.cname}*)it.data, indent_count);')
|
||||
} else if sym.kind == .function {
|
||||
g.auto_str_funcs.writeln('\t\tres = ${parent_str_fn_name}();')
|
||||
} else {
|
||||
g.auto_str_funcs.writeln('\t\tres = ${parent_str_fn_name}(*(${sym.cname}*)it.data);')
|
||||
}
|
||||
|
@ -162,7 +162,8 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr_with_cast(expr, typ, typ)
|
||||
} else {
|
||||
} else if typ.has_flag(.option) {
|
||||
// only Option fn receive argument
|
||||
g.expr_with_cast(expr, typ, typ)
|
||||
}
|
||||
g.write(')')
|
||||
|
15
vlib/v/tests/print_fn_test.v
Normal file
15
vlib/v/tests/print_fn_test.v
Normal file
@ -0,0 +1,15 @@
|
||||
struct Foo {
|
||||
mut:
|
||||
f ?fn (int)
|
||||
}
|
||||
|
||||
fn test_print_fn() {
|
||||
a := fn (a string) int {
|
||||
return 1
|
||||
}
|
||||
println(a)
|
||||
|
||||
foo := Foo{}
|
||||
println(foo.f)
|
||||
assert foo.f == none
|
||||
}
|
Loading…
Reference in New Issue
Block a user