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

Problems with assert in function definition #109

Closed
Alexander-Schiendorfer opened this Issue Aug 10, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@Alexander-Schiendorfer

Alexander-Schiendorfer commented Aug 10, 2016

Hi,

I would like to add some assertions to a function that returns "array[int,int] of int" (in reality, an adjacency matrix).

function array[int, int] of int: doSomething(array[int, int] of int: edges) =
assert(true,
"This should work",
edges);

output[ "\(doSomething([| 5, 3, 5 | 1, 2, 3 |]))" ];
solve satisfy;

which does not work and returns:

MiniZinc: type error: no function or predicate with this signature found: `assert(bool,string,array[int,int] of int)'

However, when doing the same with just an int, everything's fine:

function int: doSomething(int: e) =
assert(true,
"This should work",
e);

output[ "\(doSomething(5))" ];
solve satisfy;

Is there a workaround?

Cheers,
Alex

@Alexander-Schiendorfer

This comment has been minimized.

Alexander-Schiendorfer commented Aug 10, 2016

For anyone running into a similar issue, here is a (not really pretty) workaround that gets the job done:

function bool: preassert(bool: expr, string: message) = 
assert(expr, message, expr);

function array[int, int] of int: doSomething(array[int, int] of int: edges) =
let {
  bool: cons = preassert(false, "Should be consistent")
} in
if cons then edges else [| |] endif;

output[ "\(doSomething([| 5, 3, 5 | 1, 2, 3 |]))" ];
solve satisfy;

@guidotack guidotack closed this in 43e5945 Nov 16, 2016

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