Skip to content

Commit

Permalink
cgen: fix regression with unalised naming conflict with C interop (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jul 3, 2023
1 parent c1550b3 commit 3f5995a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vlib/v/gen/c/struct.v
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions vlib/v/tests/modules/sub/foo/c/foo.h
@@ -0,0 +1,5 @@
typedef struct sub_foo sub_foo;

struct sub_foo {
int a;
};
7 changes: 7 additions & 0 deletions 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"
Empty file.
7 changes: 7 additions & 0 deletions vlib/v/tests/modules/sub/sub_test.v
@@ -0,0 +1,7 @@
import sub

fn test_vmain() {
sub_foo := &sub.Foo{}

dump(sub_foo)
}

0 comments on commit 3f5995a

Please sign in to comment.