Skip to content

fix: string array sort with custom comparator#316

Merged
cs01 merged 3 commits intomainfrom
fix-string-sort-comparator
Mar 13, 2026
Merged

fix: string array sort with custom comparator#316
cs01 merged 3 commits intomainfrom
fix-string-sort-comparator

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 13, 2026

Summary

  • ["c","a","b"].sort((a, b) => ...) was silently broken — comparator received raw pointer values as doubles instead of string args
  • root cause: sort codegen always dispatched to numeric sort loop (loading doubles from %Array), and callback param type hint only filled first param
  • added generateStringSortWithFn that uses %StringArray struct and passes i8* strings
  • fixed orchestrator to fill callback param type hints for ALL arrow function params, not just the first

Test plan

  • new fixture arrays/string-sort-comparator.ts — ascending and descending custom sort
  • npm run verify:quick passes (self-hosting + all tests)
  • works on both JS and native compiler

@cs01 cs01 merged commit f66fb20 into main Mar 13, 2026
12 checks passed
@cs01 cs01 deleted the fix-string-sort-comparator branch March 19, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant