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.
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 objectx
.The evaluation of
=
calls "equals" which uses the following code fromIPGMContext::operator==
to check equality of object references (as opposed to simple numbers):But guards in a composite state or model use
HLPContext
instead ofIPGMContext
, andHLPContext::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 useslhs.object_ == rhs.object_
. We cannot simply copy this because theHLPContext
class doesn't have theobject_
member. (Was this omitted for efficiency?) A possible solution is to addobject_
toHLPContext
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.