Skip to content

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

Description

@angee

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions