1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix fn variable name using reserved c word (fix #15647) (#15648)

This commit is contained in:
yuyi 2022-09-04 22:50:41 +08:00 committed by GitHub
parent 436b19c408
commit d0d5f1d4e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -339,7 +339,8 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
''
}
g.write('$ret_styp ($msvc_call_conv*${g.get_ternary_name(ident.name)}) (')
fn_name := c_name(g.get_ternary_name(ident.name))
g.write('$ret_styp ($msvc_call_conv*$fn_name) (')
def_pos := g.definitions.len
g.fn_decl_params(func.func.params, unsafe { nil }, false)
g.definitions.go_back(g.definitions.len - def_pos)

View File

@ -65,7 +65,7 @@ fn (mut g Gen) unwrap(typ ast.Type) Type {
// generate function variable definition, e.g. `void (*var_name) (int, string)`
fn (mut g Gen) fn_var_signature(return_type ast.Type, arg_types []ast.Type, var_name string) string {
ret_styp := g.typ(return_type)
mut sig := '$ret_styp (*$var_name) ('
mut sig := '$ret_styp (*${c_name(var_name)}) ('
for j, arg_typ in arg_types {
arg_sym := g.table.sym(arg_typ)
if arg_sym.info is ast.FnType {

View File

@ -0,0 +1,11 @@
fn ret_int() fn (int) int {
return fn (i int) int {
return i
}
}
fn test_fn_var_name_using_reserved() {
new := ret_int()
println(new(42))
assert new(42) == 42
}