Skip to content

Commit

Permalink
Fix false-positive missing enum2int warning
Browse files Browse the repository at this point in the history
Fixes #887
  • Loading branch information
cyderize committed Feb 28, 2025
1 parent 98bae86 commit 56d6872
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Bug fixes:
comprehensions, leading to an internal error (:bugref:`879`).
- Fix false-positive implicit enum coercion warnings when calling ``card`` and
some inequality operators.
- Fix false-positive implicit enum coercion warnings for calls with
comprehension arguments (:bugref:`887`).
- Recursively type check type-insts of variable declarations and function
items.

Expand Down
5 changes: 5 additions & 0 deletions lib/typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3034,7 +3034,12 @@ class Typer {
}
Type t_before = Expression::type(c_e);
Type t = fi->argtype(_env, args, i).elemType(_env);
// Call to enum2int would have been removed when processing the comprehension,
// so don't warn here
bool warnImplicitEnum2Int = _env.warnImplicitEnum2Int;
_env.warnImplicitEnum2Int = false;
c_e = add_coercion(_env, _model, c_e, t)();
_env.warnImplicitEnum2Int = warnImplicitEnum2Int;
Type t_after = Expression::type(c_e);
if (t_before != t_after) {
if (indexTuple != nullptr) {
Expand Down
11 changes: 11 additions & 0 deletions tests/spec/unit/regression/github_887.mzn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/***
!Test
solvers: [gecode]
options:
-Werror: true
expected: !Result
status: SATISFIED
***/

enum Foo = {A};
output show({enum2int(x) | x in Foo});

0 comments on commit 56d6872

Please sign in to comment.