1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix array_sort by different order of a/b (#9106)

This commit is contained in:
yuyi
2021-03-04 18:19:02 +08:00
committed by GitHub
parent d08f994e19
commit 2b9ffbda42
3 changed files with 20 additions and 6 deletions

View File

@@ -219,8 +219,10 @@ fn (mut g Gen) gen_array_sort(node ast.CallExpr) {
is_default = true
} else {
infix_expr := node.args[0].expr as ast.InfixExpr
is_default = '$infix_expr.left' in ['a', 'b'] && '$infix_expr.right' in ['a', 'b']
is_reverse = infix_expr.op == .gt
left_name := '$infix_expr.left'
is_default = left_name in ['a', 'b'] && '$infix_expr.right' in ['a', 'b']
is_reverse = (left_name.starts_with('a') && infix_expr.op == .gt)
|| (left_name.starts_with('b') && infix_expr.op == .lt)
}
if is_default {
// users.sort() or users.sort(a > b)