IIIM-IS / AERA

Other
12 stars 4 forks source link

Unexpected result for equal operator in cst and mdl guards #133

Open jefft0 opened 3 years ago

jefft0 commented 3 years ago

In a program guard, you can have a check like the following to make sure the object in variable A (from one of the patterns) is the object x.

(= A x)

The evaluation of = calls "equals" which uses the following code from IPGMContext::operator== to check equality of object references (as opposed to simple numbers):

if (lhs.data_ == REFERENCE && lhs.index_ == 0 &&
  rhs.data_ == REFERENCE && rhs.index_ == 0) // both point to an object's head, not one of its members.
  return lhs.object_ == rhs.object_;

But guards in a composite state or model use HLPContext instead of IPGMContext, and HLPContext::operator== doesn't have an equality check for references. In fact, it only has the check for non-reference values. When the check for non-reference values is used on reference values, the result is unpredictable, especially when one references an actual object and the other references a variable. So the guard above, used in a composite state or model, does not work as expected.

The code above from IPGMContext checks for a reference value and uses lhs.object_ == rhs.object_. We cannot simply copy this because the HLPContext class doesn't have the object_ member. (Was this omitted for efficiency?) A possible solution is to add object_ to HLPContext so that it can check for equality of reference values. If not, then at a minimum using = with reference values in the guard of a composite state or model should be an error.

jefft0 commented 3 years ago

As a prerequisite, must merge the bug fix in pull request #144.