mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
07459a77e3
commit
d46b930c71
@ -1251,7 +1251,7 @@ struct Coord {
|
||||
z int
|
||||
}
|
||||
|
||||
fn test__array_struct_contains() {
|
||||
fn test_array_struct_contains() {
|
||||
mut coords := []Coord{}
|
||||
coord_1 := Coord{
|
||||
x: 1
|
||||
@ -1265,3 +1265,16 @@ fn test__array_struct_contains() {
|
||||
assert exists == true
|
||||
assert not_exists == false
|
||||
}
|
||||
|
||||
fn test_array_struct_ref_contains() {
|
||||
mut coords := []&Coord{}
|
||||
coord_1 := &Coord{
|
||||
x: 1
|
||||
y: 2
|
||||
z: -1
|
||||
}
|
||||
coords << coord_1
|
||||
exists := coord_1 in coords
|
||||
println(exists)
|
||||
assert exists == true
|
||||
}
|
||||
|
@ -406,29 +406,22 @@ fn (mut g Gen) gen_array_contains_method(left_type table.Type) string {
|
||||
mut fn_builder := strings.new_builder(512)
|
||||
fn_builder.writeln('static bool ${fn_name}($left_type_str a, $elem_type_str v) {')
|
||||
fn_builder.writeln('\tfor (int i = 0; i < a.len; ++i) {')
|
||||
match elem_sym.kind {
|
||||
.string {
|
||||
if elem_sym.kind == .string {
|
||||
fn_builder.writeln('\t\tif (string_eq((*(string*)array_get(a, i)), v)) {')
|
||||
}
|
||||
.array {
|
||||
} else if elem_sym.kind == .array && left_info.elem_type.nr_muls() == 0 {
|
||||
ptr_typ := g.gen_array_equality_fn(left_info.elem_type)
|
||||
fn_builder.writeln('\t\tif (${ptr_typ}_arr_eq(*($elem_type_str*)array_get(a, i), v)) {')
|
||||
}
|
||||
.function {
|
||||
} else if elem_sym.kind == .function {
|
||||
fn_builder.writeln('\t\tif ((*(voidptr*)array_get(a, i)) == v) {')
|
||||
}
|
||||
.map {
|
||||
} else if elem_sym.kind == .map && left_info.elem_type.nr_muls() == 0 {
|
||||
ptr_typ := g.gen_map_equality_fn(left_info.elem_type)
|
||||
fn_builder.writeln('\t\tif (${ptr_typ}_map_eq(*($elem_type_str*)array_get(a, i), v)) {')
|
||||
}
|
||||
.struct_ {
|
||||
} else if elem_sym.kind == .struct_ && left_info.elem_type.nr_muls() == 0 {
|
||||
ptr_typ := g.gen_struct_equality_fn(left_info.elem_type)
|
||||
fn_builder.writeln('\t\tif (${ptr_typ}_struct_eq(*($elem_type_str*)array_get(a, i), v)) {')
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fn_builder.writeln('\t\tif ((*($elem_type_str*)array_get(a, i)) == v) {')
|
||||
}
|
||||
}
|
||||
fn_builder.writeln('\t\t\treturn true;')
|
||||
fn_builder.writeln('\t\t}')
|
||||
fn_builder.writeln('\t}')
|
||||
|
Loading…
Reference in New Issue
Block a user