diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index c3c03cd803..abc8e22d73 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -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 +} diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index a4bf180a30..415ac23519 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -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)