cgen: fix generic_fn_name generating incorrect names for C structs

This commit is contained in:
Dylan Donnell 2025-08-24 23:41:21 +02:00
parent 3b25f1e101
commit 6c1085a4f0
4 changed files with 25 additions and 1 deletions

View file

@ -1271,7 +1271,8 @@ fn (mut g Gen) generic_fn_name(types []ast.Type, before string) string {
// `foo[int]()` => `foo_T_int()` // `foo[int]()` => `foo_T_int()`
mut name := before + '_T' mut name := before + '_T'
for typ in types { 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 return name
} }

View file

@ -0,0 +1,9 @@
// foo.h
#ifndef TEST_H
#define TEST_H
struct foo {
int a;
};
#endif

View 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)
}

View file