mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen: fix generic_fn_name generating incorrect names for C structs
This commit is contained in:
parent
3b25f1e101
commit
6c1085a4f0
4 changed files with 25 additions and 1 deletions
|
@ -1271,7 +1271,8 @@ fn (mut g Gen) generic_fn_name(types []ast.Type, before string) string {
|
|||
// `foo[int]()` => `foo_T_int()`
|
||||
mut name := before + '_T'
|
||||
for typ in types {
|
||||
name += '_' + strings.repeat_string('__ptr__', typ.nr_muls()) + g.styp(typ.set_nr_muls(0))
|
||||
name += '_' + strings.repeat_string('__ptr__', typ.nr_muls()) +
|
||||
g.styp(typ.set_nr_muls(0)).replace(' ', '_')
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
|
9
vlib/v/tests/generics/foo.h
Normal file
9
vlib/v/tests/generics/foo.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
// foo.h
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
|
||||
struct foo {
|
||||
int a;
|
||||
};
|
||||
|
||||
#endif
|
14
vlib/v/tests/generics/generic_struct_cstruct_test.v
Normal file
14
vlib/v/tests/generics/generic_struct_cstruct_test.v
Normal file
|
@ -0,0 +1,14 @@
|
|||
#insert "@VMODROOT/foo.h"
|
||||
|
||||
struct C.foo {
|
||||
a int
|
||||
}
|
||||
|
||||
fn ref[T](x T) &T {
|
||||
return &x
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
a := C.foo{}
|
||||
b := ref(a)
|
||||
}
|
0
vlib/v/tests/generics/v.mod
Normal file
0
vlib/v/tests/generics/v.mod
Normal file
Loading…
Add table
Add a link
Reference in a new issue