1
0
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:
yuyi 2023-02-15 17:27:21 +08:00 committed by GitHub
parent 4691c5d637
commit 5a8c433548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -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(')')

View File

@ -0,0 +1,7 @@
fn foo() {
}
fn test_print_reference_function() {
println(&foo)
assert '${&foo}' == 'fn ()'
}