fix(sort): avoid int64 overflow comparing large integers (#2771)

The int/int comparator returned int(lhs - rhs); the int64 subtraction overflows for large-magnitude values, giving the wrong sign. Compare directly instead.

Co-authored-by: max <max@example.com>
This commit is contained in:
maximilize
2026-08-03 13:14:29 +10:00
committed by GitHub
co-authored by max
parent b7c9d01670
commit 0d4490b875
2 changed files with 15 additions and 1 deletions
+9
View File
@@ -171,6 +171,15 @@ var sortByOperatorScenarios = []expressionScenario{
"D0, P[], (!!seq)::# abc\n- def\n# ghi\n",
},
},
{
skipDoc: true,
description: "Sort large integers (no int64 subtraction overflow)",
document: "[5000000000000000000, -5000000000000000000]",
expression: `sort`,
expected: []string{
"D0, P[], (!!seq)::[-5000000000000000000, 5000000000000000000]\n",
},
},
}
func TestSortByOperatorScenarios(t *testing.T) {