mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: add interface case for gen_struct_equality_fn (#12094)
This commit is contained in:
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)')
|
||||
} else if field_type.sym.kind == .function {
|
||||
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 {
|
||||
fn_builder.write_string('a.$field_name == b.$field_name')
|
||||
}
|
||||
|
23
vlib/v/tests/struct_auto_eq_gen_interface_test.v
Normal file
23
vlib/v/tests/struct_auto_eq_gen_interface_test.v
Normal file
@ -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
Block a user