Rule firing although guard should fail
I am using the 32-bit-Version of SWI-Prolog 8.2.0 on Windows 10 64-bit.
In the attached file, testchr.txt (rename to .pl before running), running testit should lead to none of the CHR rules to be executed.
testit adds the constraint c2(_Addr) to the store. For c2_rule to fire, c1(Dest) must fail. The expected behaviour is for c1(Dest) not to fail, as Dest is unified with _Addr from the testit-call, which is a variable and not an integer. Thus, the expected behaviour is for c2_rule not to fire.
However, when running testit, we get the following output:
>swipl
Welcome to SWI-Prolog (threaded, 32 bits, version 8.2.0)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
1 ?- use_module(testchr).
true.
2 ?- testit.
c2_rule(_97180)
true.
3 ?-
The output c2_rule indicates that the rule c2_rule was indeed executed.
The example comes from a much larger CHR code-base, but has been distilled down to the minimal example. As soon as the rule c1_rule is removed, the system behaves as expected.
I have also attached an execution trace in testchr_trace.txt.
I'm not a CHR user. https://www.swi-prolog.org/pldoc/man?section=chr-syntax doesn't say anything about negating the combined guard and body though.
Please raise this at the CHR community or the forum. CHR has had very few bugs. Its a mostly sleeping sub project. Its main author (Tom Schrijvers) should probably get involved if this is a real bug.
I have just contacted Tom on this issue.