diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index 04d2652a0b..e47636e647 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -858,10 +858,18 @@ fn (mut g Gen) gen_array_index_methods() { fn_builder.writeln('\t\tif (${ptr_typ}_struct_eq(*pelem, v)) {') } else if elem_sym.kind == .interface_ { ptr_typ := g.equality_fn(info.elem_type) - fn_builder.writeln('\t\tif (${ptr_typ}_interface_eq(*pelem, v)) {') + if info.elem_type.is_ptr() { + fn_builder.writeln('\t\tif (${ptr_typ}_interface_eq(**pelem, *v)) {') + } else { + fn_builder.writeln('\t\tif (${ptr_typ}_interface_eq(*pelem, v)) {') + } } else if elem_sym.kind == .sum_type { ptr_typ := g.equality_fn(info.elem_type) - fn_builder.writeln('\t\tif (${ptr_typ}_sumtype_eq(*pelem, v)) {') + if info.elem_type.is_ptr() { + fn_builder.writeln('\t\tif (${ptr_typ}_sumtype_eq(**pelem, *v)) {') + } else { + fn_builder.writeln('\t\tif (${ptr_typ}_sumtype_eq(*pelem, v)) {') + } } else if elem_sym.kind == .alias { ptr_typ := g.equality_fn(info.elem_type) fn_builder.writeln('\t\tif (${ptr_typ}_alias_eq(*pelem, v)) {') diff --git a/vlib/v/tests/array_of_reference_sumtype_append_test.v b/vlib/v/tests/array_of_reference_sumtype_test.v similarity index 68% rename from vlib/v/tests/array_of_reference_sumtype_append_test.v rename to vlib/v/tests/array_of_reference_sumtype_test.v index 581027886b..88962e12a0 100644 --- a/vlib/v/tests/array_of_reference_sumtype_append_test.v +++ b/vlib/v/tests/array_of_reference_sumtype_test.v @@ -1,11 +1,14 @@ struct Element { AbstractNode +mut: name string + value string attributes []&Attribute } struct Attribute { AbstractNode +mut: name string value string } @@ -21,7 +24,11 @@ pub fn (mut n AbstractNode) append_child(child &Node) { n.child_nodes << child } -fn test_array_of_reference_sumtype_append() { +pub fn (n &AbstractNode) has_child(child &Node) int { + return n.child_nodes.index(child) +} + +fn test_array_of_reference_sumtype() { mut parent := &Element{ name: 'parent' } @@ -30,6 +37,9 @@ fn test_array_of_reference_sumtype_append() { } parent.append_child(child) + ret := parent.has_child(child) + println(ret) dump(parent) assert parent.child_nodes[0].name == 'child' + assert ret == 0 }