Skip to content

Commit 70f694f

Browse files
authored
cgen: fix generic_fn_name generating incorrect names for C structs (#25164)
1 parent 3b25f1e commit 70f694f

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,8 @@ fn (mut g Gen) generic_fn_name(types []ast.Type, before string) string {
12711271
// `foo[int]()` => `foo_T_int()`
12721272
mut name := before + '_T'
12731273
for typ in types {
1274-
name += '_' + strings.repeat_string('__ptr__', typ.nr_muls()) + g.styp(typ.set_nr_muls(0))
1274+
name += '_' + strings.repeat_string('__ptr__', typ.nr_muls()) +
1275+
g.styp(typ.set_nr_muls(0)).replace(' ', '_')
12751276
}
12761277
return name
12771278
}

‎vlib/v/tests/generics/foo.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// foo.h
2+
#ifndef TEST_H
3+
#define TEST_H
4+
5+
struct foo {
6+
int a;
7+
};
8+
9+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#insert "@VMODROOT/foo.h"
2+
3+
struct C.foo {
4+
a int
5+
}
6+
7+
fn ref[T](x T) &T {
8+
return &x
9+
}
10+
11+
fn test_main() {
12+
a := C.foo{}
13+
b := ref(a)
14+
}

‎vlib/v/tests/generics/v.mod‎

Whitespace-only changes.

0 commit comments

Comments
 (0)