v.gen.c: fix compilation of `if c_struct_1 != c_struct_2 {`

pull/12042/head
Delyan Angelov 2021-10-02 15:05:57 +03:00
parent cc4af235f3
commit c86935309e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 23 additions and 1 deletions

View File

@ -7,7 +7,11 @@ import v.ast
fn (mut g Gen) equality_fn(typ ast.Type) string { fn (mut g Gen) equality_fn(typ ast.Type) string {
g.needed_equality_fns << typ.set_nr_muls(0) 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() { fn (mut g Gen) gen_equality_fns() {

View File

@ -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)) {

View File

@ -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')
}
}