Skip to content

Commit

Permalink
mathematica: fix sort predicate stability
Browse files Browse the repository at this point in the history
Incorrect sorting predicate was found as part of
NixOS/nix#12106 where `nix` was crashing on
the code like:

    $ nix eval --expr 'builtins.sort (a: b: true) [ 1 2 3 ]'
    ...
    Aborted (core dumped)

Note: the crash happens here because sorting predicate does not
implement `lessThan` and triggers assertion failures for
`std::stable_sort` that backs `builtins.sort`.

The change restores `lessThan` semantic for version sorting.
  • Loading branch information
trofi committed Dec 26, 2024
1 parent 9ceb117 commit bf74032
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkgs/applications/science/math/mathematica/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
let
versions = callPackage ./versions.nix { };

matching-versions = lib.sort (v1: v2: lib.versionAtLeast v1.version v2.version) (
matching-versions = lib.sort (v1: v2: lib.versionOlder v2.version v1.version) (
lib.filter (
v: v.lang == lang && (version == null || isMatching v.version version) && matchesDoc v
) versions
Expand Down

0 comments on commit bf74032

Please sign in to comment.