Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jefft0 opened this issue Jan 21, 2021 · 1 comment
Open

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

jefft0 opened this issue Jan 21, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@jefft0
Copy link
Collaborator

jefft0 commented Jan 21, 2021

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 jefft0 added the bug Something isn't working label Jan 21, 2021
@jefft0 jefft0 changed the title Equal operator in cst and mdl guards always returns false Unexpected result for equal operator in cst and mdl guards Jan 21, 2021
@jefft0 jefft0 added this to the release1 milestone Mar 4, 2021
@jefft0 jefft0 modified the milestones: release1, RELEASE_1 Mar 16, 2021
@jefft0
Copy link
Collaborator Author

jefft0 commented Mar 17, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant