mirror of
https://github.com/vlang/v.git
synced 2025-09-09 15:27:05 -04:00
cgen: fix codegen for a.index/1, where a is []Fn (#20849)
This commit is contained in:
parent
d2af0dc96a
commit
497b613023
35
vlib/builtin/array_index_test.v
Normal file
35
vlib/builtin/array_index_test.v
Normal file
@ -0,0 +1,35 @@
|
||||
fn test_index_of_ints() {
|
||||
ia := [1, 2, 3]
|
||||
ii := ia.index(2)
|
||||
dump(ii)
|
||||
assert ii == 1
|
||||
}
|
||||
|
||||
fn test_index_of_strings() {
|
||||
sa := ['a', 'b', 'c']
|
||||
si := sa.index('b')
|
||||
dump(si)
|
||||
assert si == 1
|
||||
}
|
||||
|
||||
fn test_index_of_voidptrs() {
|
||||
pa := [voidptr(123), voidptr(45), voidptr(99)]
|
||||
pi := pa.index(voidptr(45))
|
||||
dump(pi)
|
||||
assert pi == 1
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
fn a() {}
|
||||
|
||||
fn b() {}
|
||||
|
||||
fn c() {}
|
||||
|
||||
fn test_index_of_fns() {
|
||||
fa := [a, b, c]
|
||||
fi := fa.index(b)
|
||||
dump(fi)
|
||||
assert fi == 1
|
||||
}
|
@ -1061,7 +1061,7 @@ fn (mut g Gen) gen_array_index_methods() {
|
||||
ptr_typ := g.equality_fn(info.elem_type)
|
||||
fn_builder.writeln('\t\tif (${ptr_typ}_arr_eq(*pelem, v)) {')
|
||||
} else if elem_sym.kind == .function && !info.elem_type.is_ptr() {
|
||||
fn_builder.writeln('\t\tif ( pelem == v) {')
|
||||
fn_builder.writeln('\t\tif ( *pelem == v) {')
|
||||
} else if elem_sym.kind == .map && !info.elem_type.is_ptr() {
|
||||
ptr_typ := g.equality_fn(info.elem_type)
|
||||
fn_builder.writeln('\t\tif (${ptr_typ}_map_eq((*pelem, v))) {')
|
||||
|
Loading…
x
Reference in New Issue
Block a user