From 165db79911cdce9824bd9e9d22b5849a491fd860 Mon Sep 17 00:00:00 2001 From: Jason N Date: Thu, 20 Apr 2023 16:06:38 +1000 Subject: [PATCH] Mark `nvalue` function as `::promise_total` --- changes.rst | 1 + share/minizinc/std/nvalue_fn.mzn | 2 +- tests/spec/unit/globals/nvalue/nvalue_total.mzn | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/spec/unit/globals/nvalue/nvalue_total.mzn diff --git a/changes.rst b/changes.rst index 7a9e884bd..453ead38c 100644 --- a/changes.rst +++ b/changes.rst @@ -51,6 +51,7 @@ Bug fixes: (:bugref:`679`). - Fix common subexpression elimination for expressions used in incompatible contexts (:bugref:`666`). +- Add missing ``::promise_total`` to functional version of ``nvalue``. Changes in the IDE: ^^^^^^^^^^^^^^^^^^^ diff --git a/share/minizinc/std/nvalue_fn.mzn b/share/minizinc/std/nvalue_fn.mzn index 0cdfbdb31..4562b2e5b 100644 --- a/share/minizinc/std/nvalue_fn.mzn +++ b/share/minizinc/std/nvalue_fn.mzn @@ -3,5 +3,5 @@ include "nvalue.mzn"; /** @group globals.alldifferent Returns the number of distinct values in \a x. */ -function var int: nvalue(array[$X] of var int: x) = +function var int: nvalue(array[$X] of var int: x) :: promise_total = let { var 0..length(x): n::is_defined_var; constraint nvalue(n,x)::defines_var(n); } in n; diff --git a/tests/spec/unit/globals/nvalue/nvalue_total.mzn b/tests/spec/unit/globals/nvalue/nvalue_total.mzn new file mode 100644 index 000000000..b4f6f14c2 --- /dev/null +++ b/tests/spec/unit/globals/nvalue/nvalue_total.mzn @@ -0,0 +1,12 @@ +/*** +!Test +solvers: [gecode] +expected: !Result + solution: !Solution + l1: 0 +***/ + +include "nvalue_fn.mzn"; + +array[1..10] of var 0..10: X; +int: l1 :: output = lb(nvalue(X));