cgen: fix generic contains method (#7618)

pull/7634/head
Swastik Baranwal 2020-12-27 23:37:53 +05:30 committed by GitHub
parent ed6ba0a2b8
commit d87011ab78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -1251,3 +1251,24 @@ fn test_struct_array_of_multi_type_index() {
println(people.index(ivan)) println(people.index(ivan))
assert people.index(ivan) == 0 assert people.index(ivan) == 0
} }
struct Coord {
x int
y int
z int
}
fn test__array_struct_contains() {
mut coords := []Coord{}
coord_1 := Coord{
x: 1
y: 2
z: -1
}
coords << coord_1
exists := coord_1 in coords
not_exists := coord_1 !in coords
println('`exists`: $exists and `not exists`: $not_exists')
assert exists == true
assert not_exists == false
}

View File

@ -38,7 +38,7 @@ fn (mut g Gen) gen_struct_equality_fn(left table.Type) string {
fn_builder.writeln('\tif (*((voidptr*)(a.$field.name)) != *((voidptr*)(b.$field.name))) {') fn_builder.writeln('\tif (*((voidptr*)(a.$field.name)) != *((voidptr*)(b.$field.name))) {')
} }
else { else {
fn_builder.writeln('\tif (a.$field.name != b.$field.name)) {') fn_builder.writeln('\tif (a.$field.name != b.$field.name) {')
} }
} }
fn_builder.writeln('\t\treturn false;') fn_builder.writeln('\t\treturn false;')