From 3f5995ace86be3153397448c7da7907de5e7d41a Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 3 Jul 2023 17:12:20 -0300 Subject: [PATCH] cgen: fix regression with unalised naming conflict with C interop (#18752) --- vlib/v/gen/c/struct.v | 7 ++++++- vlib/v/tests/modules/sub/foo.v | 10 ++++++++++ vlib/v/tests/modules/sub/foo/c/foo.h | 5 +++++ vlib/v/tests/modules/sub/foo/c/foo.v | 7 +++++++ vlib/v/tests/modules/sub/foo/c/v.mod | 0 vlib/v/tests/modules/sub/sub_test.v | 7 +++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/modules/sub/foo.v create mode 100644 vlib/v/tests/modules/sub/foo/c/foo.h create mode 100644 vlib/v/tests/modules/sub/foo/c/foo.v create mode 100644 vlib/v/tests/modules/sub/foo/c/v.mod create mode 100644 vlib/v/tests/modules/sub/sub_test.v diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index a6222b5a6..d19d2edb7 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -22,7 +22,12 @@ fn (mut g Gen) struct_init(node ast.StructInit) { g.empty_line = false g.write(s) } - styp := g.typ(g.table.unaliased_type(node.typ)).replace('*', '') + unalised_typ := g.table.unaliased_type(node.typ) + styp := if g.table.sym(unalised_typ).language == .v { + g.typ(unalised_typ).replace('*', '') + } else { + g.typ(node.typ) + } mut shared_styp := '' // only needed for shared x := St{... if styp in c.skip_struct_init { // needed for c++ compilers diff --git a/vlib/v/tests/modules/sub/foo.v b/vlib/v/tests/modules/sub/foo.v new file mode 100644 index 000000000..6b1d9e9b3 --- /dev/null +++ b/vlib/v/tests/modules/sub/foo.v @@ -0,0 +1,10 @@ +module sub + +import sub.foo.c + +[typedef] +struct C.sub_foo { + a int +} + +pub type Foo = C.sub_foo diff --git a/vlib/v/tests/modules/sub/foo/c/foo.h b/vlib/v/tests/modules/sub/foo/c/foo.h new file mode 100644 index 000000000..bdfe51e56 --- /dev/null +++ b/vlib/v/tests/modules/sub/foo/c/foo.h @@ -0,0 +1,5 @@ +typedef struct sub_foo sub_foo; + +struct sub_foo { + int a; +}; \ No newline at end of file diff --git a/vlib/v/tests/modules/sub/foo/c/foo.v b/vlib/v/tests/modules/sub/foo/c/foo.v new file mode 100644 index 000000000..199d3d13a --- /dev/null +++ b/vlib/v/tests/modules/sub/foo/c/foo.v @@ -0,0 +1,7 @@ +module c + +pub const used_import = 1 + +#flag -I @VMODROOT + +#include "foo.h" diff --git a/vlib/v/tests/modules/sub/foo/c/v.mod b/vlib/v/tests/modules/sub/foo/c/v.mod new file mode 100644 index 000000000..e69de29bb diff --git a/vlib/v/tests/modules/sub/sub_test.v b/vlib/v/tests/modules/sub/sub_test.v new file mode 100644 index 000000000..4020d2897 --- /dev/null +++ b/vlib/v/tests/modules/sub/sub_test.v @@ -0,0 +1,7 @@ +import sub + +fn test_vmain() { + sub_foo := &sub.Foo{} + + dump(sub_foo) +} -- 2.39.5