From 60240d8cf137d41882ce32a894554aa16440adad Mon Sep 17 00:00:00 2001 From: Jason N Date: Tue, 29 Oct 2024 15:29:14 +1100 Subject: [PATCH] Fix type inst for array assignment generators Fixes #858 --- changes.rst | 1 + lib/typecheck.cpp | 10 ++++++++++ tests/spec/unit/regression/github_858.mzn | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/spec/unit/regression/github_858.mzn diff --git a/changes.rst b/changes.rst index 734e2fb71..596cbc5f5 100644 --- a/changes.rst +++ b/changes.rst @@ -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: diff --git a/lib/typecheck.cpp b/lib/typecheck.cpp index c4a128a07..2280b7137 100644 --- a/lib/typecheck.cpp +++ b/lib/typecheck.cpp @@ -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 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) { diff --git a/tests/spec/unit/regression/github_858.mzn b/tests/spec/unit/regression/github_858.mzn new file mode 100644 index 000000000..bffa1b7bd --- /dev/null +++ b/tests/spec/unit/regression/github_858.mzn @@ -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", +];