From c86935309e10cb0564f6676971942e86cffa4548 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 2 Oct 2021 15:05:57 +0300 Subject: [PATCH] v.gen.c: fix compilation of `if c_struct_1 != c_struct_2 {` --- vlib/v/gen/c/auto_eq_methods.v | 6 +++++- vlib/v/gen/c/testdata/compare_structs.c.must_have | 4 ++++ vlib/v/gen/c/testdata/compare_structs.vv | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 vlib/v/gen/c/testdata/compare_structs.c.must_have create mode 100644 vlib/v/gen/c/testdata/compare_structs.vv diff --git a/vlib/v/gen/c/auto_eq_methods.v b/vlib/v/gen/c/auto_eq_methods.v index 0811f71438..d02cac0789 100644 --- a/vlib/v/gen/c/auto_eq_methods.v +++ b/vlib/v/gen/c/auto_eq_methods.v @@ -7,7 +7,11 @@ import v.ast fn (mut g Gen) equality_fn(typ ast.Type) string { g.needed_equality_fns << typ.set_nr_muls(0) - return g.typ(g.unwrap_generic(typ).set_nr_muls(0)) + t1 := g.unwrap_generic(typ) + t2 := t1.set_nr_muls(0) + st2 := g.typ(t2) + res := st2.replace('struct ', '') + return res } fn (mut g Gen) gen_equality_fns() { diff --git a/vlib/v/gen/c/testdata/compare_structs.c.must_have b/vlib/v/gen/c/testdata/compare_structs.c.must_have new file mode 100644 index 0000000000..19804bcc14 --- /dev/null +++ b/vlib/v/gen/c/testdata/compare_structs.c.must_have @@ -0,0 +1,4 @@ +struct Something aaa = (struct Something){.fint = 0,.ff32 = 0,.fchar = 0,}; +struct Something bbb = (struct Something){.fint = 0,.ff32 = 0,.fchar = 0,}; +if (Something_struct_eq(aaa, bbb)) { + diff --git a/vlib/v/gen/c/testdata/compare_structs.vv b/vlib/v/gen/c/testdata/compare_structs.vv new file mode 100644 index 0000000000..aaf97ef6f1 --- /dev/null +++ b/vlib/v/gen/c/testdata/compare_structs.vv @@ -0,0 +1,14 @@ + +struct C.Something { + fint int + ff32 f32 + fchar char +} + +fn main() { + aaa := C.Something{} + bbb := C.Something{} + if aaa == bbb { + println('ok') + } +}