mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix for passing functions as voidptr args
This commit is contained in:
parent
e3f7681e89
commit
e5a5e76a30
@ -834,3 +834,37 @@ fn test_string_alias() {
|
||||
ss := s + '!'
|
||||
}
|
||||
*/
|
||||
|
||||
// sort an array of structs, by their string field values
|
||||
|
||||
struct Ka {
|
||||
s string
|
||||
i int
|
||||
}
|
||||
|
||||
fn test_sorter() {
|
||||
mut arr := [
|
||||
Ka{
|
||||
s: 'bbb'
|
||||
i: 100
|
||||
},
|
||||
Ka{
|
||||
s: 'aaa'
|
||||
i: 101
|
||||
},
|
||||
Ka{
|
||||
s: 'ccc'
|
||||
i: 102
|
||||
}
|
||||
]
|
||||
cmp := fn (a, b &Ka) int {
|
||||
return compare_strings(a.s, b.s)
|
||||
}
|
||||
arr.sort_with_compare(cmp)
|
||||
assert arr[0].s == 'aaa'
|
||||
assert arr[0].i == 101
|
||||
assert arr[1].s == 'bbb'
|
||||
assert arr[1].i == 100
|
||||
assert arr[2].s == 'ccc'
|
||||
assert arr[2].i == 102
|
||||
}
|
||||
|
@ -644,7 +644,10 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type table.Type) {
|
||||
}
|
||||
}
|
||||
if !g.is_json_fn {
|
||||
g.write('(voidptr)&/*qq*/')
|
||||
arg_typ_sym := g.table.get_type_symbol(arg.typ)
|
||||
if arg_typ_sym.kind != .function {
|
||||
g.write('(voidptr)&/*qq*/')
|
||||
}
|
||||
}
|
||||
}
|
||||
g.expr_with_cast(arg.expr, arg.typ, expected_type)
|
||||
|
Loading…
Reference in New Issue
Block a user