Skip to content

Commit

Permalink
Fix type inst for array assignment generators
Browse files Browse the repository at this point in the history
Fixes #858
  • Loading branch information
cyderize committed Oct 29, 2024
1 parent b527d89 commit 60240d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bug fixes:
booleans.
- Fix memory leak in overflow handler.
- Fix crash when calling ``outputJSON`` (:bugref:`856`).
- Fix incorrect typing of arrays in assignment generators (:bugref:`858`).

.. _v2.8.7:

Expand Down
10 changes: 10 additions & 0 deletions lib/typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,16 @@ class Typer {
const Type& ty_where = Expression::type(c->where(gen_i));
c->decl(gen_i, 0)->type(ty_where);
c->decl(gen_i, 0)->ti()->type(ty_where);
if (ty_where.structBT()) {
c->decl(gen_i, 0)->ti()->setStructDomain(_env, ty_where);
} else if (ty_where.dim() > 0) {
GCLock lock;
std::vector<TypeInst*> ranges(ty_where.dim());
for (int i = 0; i < ty_where.dim(); i++) {
ranges[i] = new TypeInst(Location().introduce(), Type::parint());
}
c->decl(gen_i, 0)->ti()->setRanges(ranges);
}
} else {
const Type& ty_in = Expression::type(g_in);
if (ty_in != Type::varsetint() && ty_in != Type::parsetint() && ty_in.dim() == 0) {
Expand Down
16 changes: 16 additions & 0 deletions tests/spec/unit/regression/github_858.mzn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/***
!Test
solvers: [gecode]
expected: !Result
solution: !Solution
_output_item: "[1][1][1]\n"
***/

array[int, int] of int: foos = [| 1, 0 |];

output [
show([ r[1] | t=foos, i in index_set_1of2(t), r=t[i, ..] ]), % error
show([ r[1] | i in index_set_1of2(foos), t=foos, r=t[i, ..] ]), % error
show([ r[1] | i in 1..1, t=foos, r=t[i, ..] ]), % error
"\n",
];

0 comments on commit 60240d8

Please sign in to comment.