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

Equality test fails if a nil value is used #717

Closed
nickbattle opened this issue Mar 15, 2020 · 1 comment
Closed

Equality test fails if a nil value is used #717

nickbattle opened this issue Mar 15, 2020 · 1 comment
Labels
bug Incorrect behaviour of the tool language Issues in parser, TC, interpreter, POG or CG Mergable A fix is available on a branch to merge for release
Milestone

Comments

@nickbattle
Copy link
Contributor

The eq clause of an invariant type produces a function of type T * T +> bool. Therefore when two values of the type are compared, the arguments to eq are converted to type T before the equality is evaluated (like any function call).

But if one of the argument values is nil, this cannot be converted to T unless it is also an optional type. That currently causes a runtime exception; it should simply return false. For example:

types
  T = nat
  eq a = b == a <> b;

functions
  f: [T] -> bool
  f(a) == a = nil;

> p f(1)
org.overture.interpreter.runtime.ValueException: Cannot convert nil (nil) to nat

The solution is to check for a nil value before calling the eq function and return false if the underlying type is not optional.

@nickbattle nickbattle added bug Incorrect behaviour of the tool language Issues in parser, TC, interpreter, POG or CG labels Mar 15, 2020
@nickbattle
Copy link
Contributor Author

Fix now available in ncb/development.

@nickbattle nickbattle added the Mergable A fix is available on a branch to merge for release label Mar 15, 2020
@idhugoid idhugoid added this to the v3.0.0 milestone Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behaviour of the tool language Issues in parser, TC, interpreter, POG or CG Mergable A fix is available on a branch to merge for release
Projects
None yet
Development

No branches or pull requests

2 participants