cgen: add interface case for gen_struct_equality_fn (#12094)
parent
a8ace2c41c
commit
cd5b304cbf
|
@ -155,6 +155,9 @@ fn (mut g Gen) gen_struct_equality_fn(left_type ast.Type) string {
|
||||||
fn_builder.write_string('${eq_fn}_alias_eq(a.$field_name, b.$field_name)')
|
fn_builder.write_string('${eq_fn}_alias_eq(a.$field_name, b.$field_name)')
|
||||||
} else if field_type.sym.kind == .function {
|
} else if field_type.sym.kind == .function {
|
||||||
fn_builder.write_string('*((voidptr*)(a.$field_name)) == *((voidptr*)(b.$field_name))')
|
fn_builder.write_string('*((voidptr*)(a.$field_name)) == *((voidptr*)(b.$field_name))')
|
||||||
|
} else if field_type.sym.kind == .interface_ {
|
||||||
|
eq_fn := g.gen_interface_equality_fn(field.typ)
|
||||||
|
fn_builder.write_string('${eq_fn}_interface_eq(a.$field_name, b.$field_name)')
|
||||||
} else {
|
} else {
|
||||||
fn_builder.write_string('a.$field_name == b.$field_name')
|
fn_builder.write_string('a.$field_name == b.$field_name')
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
interface IExample {
|
||||||
|
thing() bool
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Foo {}
|
||||||
|
|
||||||
|
fn (n Foo) thing() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Test {
|
||||||
|
a IExample
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new() Test {
|
||||||
|
return Test{Foo{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_struct_auto_eq_gen_interface_case() {
|
||||||
|
w1 := new()
|
||||||
|
w2 := new()
|
||||||
|
assert w1 == w2
|
||||||
|
}
|
Loading…
Reference in New Issue