mirror of
https://github.com/vlang/v.git
synced 2025-09-09 23:39:39 -04:00
parent
c85232ef1f
commit
adf10f88cf
@ -611,7 +611,8 @@ fn (mut g Gen) gen_array_sort(node ast.CallExpr) {
|
||||
comparison_type = g.unwrap(infix_expr.left_type.set_nr_muls(0))
|
||||
left_name := infix_expr.left.str()
|
||||
if left_name.len > 1 {
|
||||
compare_fn += '_by' + left_name[1..].replace_each(['.', '_', '[', '_', ']', '_'])
|
||||
compare_fn += '_by' +
|
||||
left_name[1..].replace_each(['.', '_', '[', '_', ']', '_', "'", '_', '"', '_', '(', '', ')', '', ',', ''])
|
||||
}
|
||||
// is_reverse is `true` for `.sort(a > b)` and `.sort(b < a)`
|
||||
is_reverse := (left_name.starts_with('a') && infix_expr.op == .gt)
|
||||
|
13
vlib/v/tests/array_sort_with_fn_call_test.v
Normal file
13
vlib/v/tests/array_sort_with_fn_call_test.v
Normal file
@ -0,0 +1,13 @@
|
||||
struct Info {
|
||||
mut:
|
||||
fields []string
|
||||
}
|
||||
|
||||
fn test_sort_with_fn_call() {
|
||||
mut info := Info{
|
||||
fields: ['aaa(', 'b(']
|
||||
}
|
||||
info.fields.sort(a.before('(').len < b.before('(').len)
|
||||
println(info.fields)
|
||||
assert info.fields == ['b(', 'aaa(']
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user