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

Invariants make OpenJML unsure about bounded variables #567

Closed
HansvdLaan opened this issue Sep 30, 2017 · 2 comments
Closed

Invariants make OpenJML unsure about bounded variables #567

HansvdLaan opened this issue Sep 30, 2017 · 2 comments
Labels

Comments

@HansvdLaan
Copy link

I'm not sure about this but I'm guessing it's a bug. It could also very well be an error on my part.
(Same goes for the title, I don't exactly know what to call this 'bug')

Consider the following class, it's part of an exercise verifying a way to model money:

public class Amount{
	
	//@ public invariant cents >= -100;
	//@ public invariant cents <= 100;
	
	//@ public invariant euros > 0 ==> cents >= 0;
	//@ public invariant euros < 0 ==> cents <= 0;

	private /*@ spec_public @*/ int cents;

	private /*@ spec_public @*/ int euros;

	//@ requires cents >= -100;
	//@ requires cents <= 100;
	//@ requires euros > 0 ==> cents >= 0;
	//@ requires euros < 0 ==> cents <= 0;
	//@ ensures this.cents >= -100;
	//@ ensures this.cents <= 100;
	//@ ensures this.euros > 0 ==> cents >= 0;
	//@ ensures this.euros < 0 ==> cents <= 0;
	public Amount2(int euros, int cents){
	  this.euros = euros;
	  this.cents = cents;
	}
	
	public /*@ pure @*/ Amount negate(){
	  return new Amount(-euros,-cents);
	}

}

OpenJML says negate is invalid with reason being : 'ex1.Amount.negate(): The prover cannot establish an assertion (Precondition: /home/fmt/eclipse-workspace/JmlTestS4/src/ex1/Amount.java:15: ) in method negate' with line 15 being '//@ requires cents >= -100;

However, the following code is correct:

public class Foo{
	
	//@ public invariant a >= -100;
	//@ public invariant a <= 100;

	private /*@ spec_public @*/ int a;

	//@ requires a >= -100;
	//@ requires a <= 100;
	//@ ensures this.a >= -100;
	//@ ensures this.a <= 100;
	public Foo(int a){
	  this.a = a;
	}
	
	public /*@ pure @*/ Foo negate(){
	  return new Foo(-a);
	}
}
@davidcok
Copy link
Member

davidcok commented Sep 30, 2017 via email

@davidcok
Copy link
Member

davidcok commented Oct 1, 2017

Adding this as a test case, but closing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants