Skip to content

Commit adf10f8

Browse files
authored
cgen: fix array sort with fn call parameter (fix #19220) (#19221)
1 parent c85232e commit adf10f8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

vlib/v/gen/c/array.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ fn (mut g Gen) gen_array_sort(node ast.CallExpr) {
611611
comparison_type = g.unwrap(infix_expr.left_type.set_nr_muls(0))
612612
left_name := infix_expr.left.str()
613613
if left_name.len > 1 {
614-
compare_fn += '_by' + left_name[1..].replace_each(['.', '_', '[', '_', ']', '_'])
614+
compare_fn += '_by' +
615+
left_name[1..].replace_each(['.', '_', '[', '_', ']', '_', "'", '_', '"', '_', '(', '', ')', '', ',', ''])
615616
}
616617
// is_reverse is `true` for `.sort(a > b)` and `.sort(b < a)`
617618
is_reverse := (left_name.starts_with('a') && infix_expr.op == .gt)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
struct Info {
2+
mut:
3+
fields []string
4+
}
5+
6+
fn test_sort_with_fn_call() {
7+
mut info := Info{
8+
fields: ['aaa(', 'b(']
9+
}
10+
info.fields.sort(a.before('(').len < b.before('(').len)
11+
println(info.fields)
12+
assert info.fields == ['b(', 'aaa(']
13+
}

0 commit comments

Comments
 (0)