Skip to content

Commit 3f222d6

Browse files
committed
Check cv flag of Ids when generating par functions
This prevents identifiers referring to structs with both par and var members from being considered par. Fixes #919
1 parent ec8556d commit 3f222d6

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

changes.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ https://github.com/MiniZinc/libminizinc/issues.
88

99
Bug fixes:
1010
^^^^^^^^^^
11-
- Fix the rewriting of the multidimensional search annotations to ensure correct coercion of arguments (:bugref:`897`).
12-
- Output location of some errors where the problematic expression previously did not have a location (:bugref:`899`).
13-
- Fix domain computation to avoid variables being moved to the output model when they are constrained (:bugref:`911`).
14-
- Fix output processing to also respect the ``-o`` flag when flattening already detects unsatisfiability (:bugref:`908`).
15-
- Report an error when solving a FlatZinc file that does not contain a solve item (:bugref:`907`).
16-
- Pass command line options to the compiler phases earlier to avoid problems with e.g. the ``--disable-warnings`` flag (:bugref:`893`).
11+
- Fix the rewriting of the multidimensional search annotations to ensure
12+
correct coercion of arguments (:bugref:`897`).
13+
- Output location of some errors where the problematic expression previously
14+
did not have a location (:bugref:`899`).
15+
- Fix domain computation to avoid variables being moved to the output model
16+
when they are constrained (:bugref:`911`).
17+
- Fix output processing to also respect the ``-o`` flag when flattening already
18+
detects unsatisfiability (:bugref:`908`).
19+
- Report an error when solving a FlatZinc file that does not contain a solve
20+
item (:bugref:`907`).
21+
- Pass command line options to the compiler phases earlier to avoid problems
22+
with e.g. the ``--disable-warnings`` flag (:bugref:`893`).
23+
- Fix incorrect generation of par versions of functions referencing top-level
24+
tuples/records containing var fields (:bugref:`919`).
1725

1826
.. _v2.9.2:
1927

lib/typecheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3568,7 +3568,8 @@ void create_par_versions(Env& env, Model* m, BottomUpIterator<Typer<true>>& bott
35683568
return isPar;
35693569
}
35703570
void vId(const Id* ident) {
3571-
if (ident->decl() != nullptr && ident->type().isvar() && ident->decl()->toplevel()) {
3571+
if (ident->decl() != nullptr && (ident->type().isvar() || ident->type().cv()) &&
3572+
ident->decl()->toplevel()) {
35723573
isPar = false;
35733574
}
35743575
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/***
2+
!Test
3+
solvers: [gecode]
4+
expected: !Result
5+
- !Solution
6+
x: 1
7+
***/
8+
9+
% Previously the compiler would generate an invalid par version of foo()
10+
% because the type of t was seen as par instead of containing var members
11+
12+
var 1..2: v;
13+
tuple(var int, int): t = (v, 1);
14+
15+
function var int: bar(var int: x) = 1;
16+
function int: bar(int: x) = 2;
17+
18+
function var int: foo() = bar(t.1);
19+
var int: x :: output = foo();
20+
21+
solve minimize v;

0 commit comments

Comments
 (0)