From 8f69bd131105adf30fdad3cd5c33cc5a29563ce8 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Wed, 27 Sep 2023 23:47:17 +0530 Subject: [PATCH] cgen: fix `type VType = &C.CType` (#19452) --- vlib/v/gen/c/cgen.v | 10 ++-------- .../c/testdata/alias_c_parent_type_decl.c.must_have | 1 + vlib/v/gen/c/testdata/alias_c_parent_type_decl.out | 0 vlib/v/gen/c/testdata/alias_c_parent_type_decl.vv | 2 ++ 4 files changed, 5 insertions(+), 8 deletions(-) create mode 100644 vlib/v/gen/c/testdata/alias_c_parent_type_decl.c.must_have create mode 100644 vlib/v/gen/c/testdata/alias_c_parent_type_decl.out create mode 100644 vlib/v/gen/c/testdata/alias_c_parent_type_decl.vv diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index ce829ef87c2d1f..13229b09668285 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1518,17 +1518,11 @@ static inline void __${sym.cname}_pushval(${sym.cname} ch, ${push_arg} val) { pub fn (mut g Gen) write_alias_typesymbol_declaration(sym ast.TypeSymbol) { parent := g.table.type_symbols[sym.parent_idx] is_c_parent := parent.name.len > 2 && parent.name[0] == `C` && parent.name[1] == `.` - mut is_typedef := false mut is_fixed_array_of_non_builtin := false - if parent.info is ast.Struct { - is_typedef = parent.info.is_typedef - } mut parent_styp := parent.cname if is_c_parent { - if !is_typedef { - parent_styp = 'struct ' + parent.cname[3..] - } else { - parent_styp = parent.cname[3..] + if sym.info is ast.Alias { + parent_styp = g.typ(sym.info.parent_type) } } else { if sym.info is ast.Alias { diff --git a/vlib/v/gen/c/testdata/alias_c_parent_type_decl.c.must_have b/vlib/v/gen/c/testdata/alias_c_parent_type_decl.c.must_have new file mode 100644 index 00000000000000..1fa0852bbb1b6a --- /dev/null +++ b/vlib/v/gen/c/testdata/alias_c_parent_type_decl.c.must_have @@ -0,0 +1 @@ +typedef struct atype* main__BType; diff --git a/vlib/v/gen/c/testdata/alias_c_parent_type_decl.out b/vlib/v/gen/c/testdata/alias_c_parent_type_decl.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/vlib/v/gen/c/testdata/alias_c_parent_type_decl.vv b/vlib/v/gen/c/testdata/alias_c_parent_type_decl.vv new file mode 100644 index 00000000000000..0623498bd29d63 --- /dev/null +++ b/vlib/v/gen/c/testdata/alias_c_parent_type_decl.vv @@ -0,0 +1,2 @@ +struct C.atype{} +type BType = &C.atype