From 58d2d79dbb333ea2993dfa60c3833c8452bf9b9e Mon Sep 17 00:00:00 2001 From: Guido Tack Date: Wed, 30 Oct 2024 10:46:23 +1100 Subject: [PATCH] Make `sort` functions return array of enum when input is array of enum. Fixes #853. --- changes.rst | 2 ++ share/minizinc/std/sort_fn.mzn | 2 +- share/minizinc/std/stdlib/stdlib_sort.mzn | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/changes.rst b/changes.rst index b3c46c189..f1050accc 100644 --- a/changes.rst +++ b/changes.rst @@ -10,6 +10,8 @@ Changes: ^^^^^^^^ - Add support for ``elseif`` in ``if then elseif endif`` expressions without an `else` branch. +- Make ``sort`` functions return array of enum when input is array of + enum (:bugref:`853`). Bug fixes: ^^^^^^^^^^ diff --git a/share/minizinc/std/sort_fn.mzn b/share/minizinc/std/sort_fn.mzn index 55ce68171..855d06507 100644 --- a/share/minizinc/std/sort_fn.mzn +++ b/share/minizinc/std/sort_fn.mzn @@ -4,7 +4,7 @@ include "sort.mzn"; Return a multiset of values that is the same as the multiset of values in \a x but in sorted order. */ -function array[int] of var int: sort(array[int] of var int: x) ::promise_total = +function array[int] of var $$E: sort(array[int] of var $$E: x) ::promise_total = let { array[1..length(x)] of var lb_array(x)..ub_array(x): y ::is_defined_var; constraint sort(x,y) ::defines_var(y); diff --git a/share/minizinc/std/stdlib/stdlib_sort.mzn b/share/minizinc/std/stdlib/stdlib_sort.mzn index 2b1fa75a0..2f66f40f4 100644 --- a/share/minizinc/std/stdlib/stdlib_sort.mzn +++ b/share/minizinc/std/stdlib/stdlib_sort.mzn @@ -17,7 +17,7 @@ The sort is stable, i.e. if \a y[\p i] = \a y[\p j] with \p i < \p j, then function array[$$E] of any $T: sort_by(array[$$E] of any $T: x, array[$$E] of float: y); /** @group stdlib.sort Return values from array \a x sorted in non-decreasing order */ -function array[$$E] of int: sort(array[$$E] of int: x); +function array[$$E] of $$F: sort(array[$$E] of $$F: x); /** @group stdlib.sort Return values from array \a x sorted in non-decreasing order */ function array[$$E] of float: sort(array[$$E] of float: x); /** @group stdlib.sort Return values from array \a x sorted in non-decreasing order */