Skip to content

Commit

Permalink
Fix handling of absent in checkRetVal
Browse files Browse the repository at this point in the history
Fixes #752
  • Loading branch information
cyderize committed Nov 20, 2023
1 parent c3bd988 commit 8561ea1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Bug fixes:
- Fix omission of error location when there is no stack trace available.
- Fix type specialisation to always make par versions of functions available
for output (:bugref:`751`).
- Fix internal error when checking return value of functions involving arrays
of optional values (:bugref:`752`).

Changes:
^^^^^^^^
Expand Down
20 changes: 14 additions & 6 deletions lib/eval_par.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,14 @@ class EvalArrayLitCopy : public EvalBase {
auto enumId = Expression::type(fi->ti()->domain()).typeId();
if (base_t.st() == Type::ST_PLAIN) {
for (unsigned int i = 0; i < v->size(); i++) {
if ((*v)[i] == env.constants.absent) {
continue;
auto* v_i = (*v)[i];
if (Expression::type(v_i).isOpt()) {
v_i = eval_par(env, v_i);
if (v_i == env.constants.absent) {
continue;
}
}
IntVal iv = eval_int(env, (*v)[i]);
IntVal iv = eval_int(env, v_i);
if (!isv->contains(iv)) {
std::ostringstream oss;
oss << "array contains value " << env.show(iv, enumId)
Expand Down Expand Up @@ -500,10 +504,14 @@ class EvalArrayLitCopy : public EvalBase {
FloatSetVal* fsv = eval_floatset(env, fi->ti()->domain());
if (base_t.st() == Type::ST_PLAIN) {
for (unsigned int i = 0; i < v->size(); i++) {
if ((*v)[i] == env.constants.absent) {
continue;
auto* v_i = (*v)[i];
if (Expression::type(v_i).isOpt()) {
v_i = eval_par(env, v_i);
if (v_i == env.constants.absent) {
continue;
}
}
FloatVal fv = eval_float(env, (*v)[i]);
FloatVal fv = eval_float(env, v_i);
if (!fsv->contains(fv)) {
std::ostringstream oss;
oss << "array contains value " << fv << " which is not contained in " << *fsv;
Expand Down
9 changes: 9 additions & 0 deletions tests/spec/unit/optional/fn_return_array_absent.mzn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/***
!Test
solvers: [gecode]
expected: !Result
solution: !Solution
x: [null]
***/
function array [int] of opt 1..3: foo() = [[1, <>][2]];
any: x :: output = foo();
21 changes: 21 additions & 0 deletions tests/spec/unit/regression/github_752.mzn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/***
!Test
solvers: [gecode]
expected: !Result
solution: !Solution
***/

% Regression test for GitHub #752

include "globals.mzn";

int: N=5;
array[1..5] of var 1..10 : x;
enum STATE = {S1, S2, S3};
% DFA to define 12*1
array [STATE,1..2] of opt STATE: trans = [| 1: 2:
| S1: S2, <>
| S2: S3, S2
| S3: <>, <>|];

constraint regular(x, trans, S1, {S3});

0 comments on commit 8561ea1

Please sign in to comment.