mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix printing a reference to a function (#17307)
This commit is contained in:
parent
4691c5d637
commit
5a8c433548
@ -139,12 +139,12 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||
is_var_mut := expr.is_auto_deref_var()
|
||||
str_fn_name := g.get_str_fn(typ)
|
||||
g.write('${str_fn_name}(')
|
||||
if str_method_expects_ptr && !is_ptr {
|
||||
g.write('&')
|
||||
} else if (!str_method_expects_ptr && is_ptr && !is_shared) || is_var_mut {
|
||||
g.write('*')
|
||||
}
|
||||
if sym.kind != .function {
|
||||
if str_method_expects_ptr && !is_ptr {
|
||||
g.write('&')
|
||||
} else if (!str_method_expects_ptr && is_ptr && !is_shared) || is_var_mut {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr_with_cast(expr, typ, typ)
|
||||
}
|
||||
g.write(')')
|
||||
|
7
vlib/v/tests/print_reference_function_test.v
Normal file
7
vlib/v/tests/print_reference_function_test.v
Normal file
@ -0,0 +1,7 @@
|
||||
fn foo() {
|
||||
}
|
||||
|
||||
fn test_print_reference_function() {
|
||||
println(&foo)
|
||||
assert '${&foo}' == 'fn ()'
|
||||
}
|
Loading…
Reference in New Issue
Block a user