New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function: invalid type error message for array index when comparing 1..n and set of int #131

Closed
angee opened this Issue Jan 19, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@angee
Member

angee commented Jan 19, 2017

I got an unexpected error when formulating my own function that returns a two-dimensional variable array, and I'm wondering if it is intentional. Let's say we are given the following two arrays that have differing first ranges, but share the second range (1..5), and I write a function as below to get either array using an integer. For the first range of the array in the signature of the function I use set of int to cover both 1..2 and 1..4.

array[1..2, 1..5] of var bool: my_array1;
array[1..4, 1..5] of var bool: my_array2;

function array[set of int, 1..5] of var bool: my_array(int:select) =
if select = 1 then my_array1
else my_array2 endif;

However, this results in the (not very helpful) error message: "MiniZinc: type error: invalid type in array index, expected 'set of int', actual 'set of int'". I presume this is because the type inst of set of int is not equivalent to 1..2 and 1..5, respectively. Now if I change set of int to the largest common range 1..4 (or any other higher range such as 1..1000) in the function, I get no error message:

function array[1..4, 1..5] of var bool: my_array(int:select) =
if select = 1 then my_array1
else my_array2 endif;

This might be expected behaviour and documented somewhere, however, it might be useful to adapt the error message so that users understand the actual problem (and realise that it is not a bug in MiniZinc). I attached a MiniZinc model that reproduces the error as text file.
function_test.txt

@guidotack

This comment has been minimized.

Member

guidotack commented Jan 19, 2017

The error message is certainly not helpful, but there is indeed an error in your model: try replacing 'set of int' by 'int' in the declaration of the function result type inst. I've fixed the error message on the develop branch.

@angee

This comment has been minimized.

Member

angee commented Jan 25, 2017

Great, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment