MiniZinc / libminizinc

The MiniZinc compiler
http://www.minizinc.org
Other
516 stars 81 forks source link

`arr[enum]` is wrong? #829

Closed LebedevRI closed 3 months ago

LebedevRI commented 3 months ago
enum B = _(2..3);
% set of int: B = 2..3; % <- works correctly

array[1..4] of var bool: q;

constraint count(q[B]) == 2;

output[show(q) ++ "\n"];
Running Untitled1.mzn
[true, true, false, false]
----------
Dekker1 commented 3 months ago

The expectation seems to be the same as in https://github.com/MiniZinc/libminizinc/issues/827. However, when the enumerated type B is coerced into integers, the first member of B will take the integer value 1. This is the expected behaviour, even when the enumerated type is an anonymous enumerated type created with a different range.

Generally it is a better approach to avoid the (automatic) coercion from enumerated types to integers in the model. You could change the model to use an enumerated type as the index set of q.

LebedevRI commented 3 months ago

I must say it feels quite surprising and really unfortunate that such lossy and bugprone coersions are allowed to happen implicitly.

Thanks.