Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JML postcondition contains class method call

Can a JML postcondition for a class method contain a call to another method call

For example I have this class:

public class A
{
    public int doA(x)
    { ... }

    public int doB(int x, int y)
    { ... }
}

For the postcondition of doB can I have: ensures doA(x) = doA(y)?

like image 909
Alina Danila Avatar asked Apr 21 '26 21:04

Alina Danila


1 Answers

Yes, provided the called method doesn't include side effects and is declared as pure:

The /@ pure @/ comment indicates that peek() is a pure method. A pure method is one that doesn't have side effects. JML only allows assertions to use pure methods. We declare peek() to be pure so it can be used in the postcondition of pop(). If JML allowed non-pure methods in assertions then we could inadvertently write specifications that had side effects. This could result in code that works when compiled with assertion checking enabled but doesn't work when assertion checking is disabled.

http://www.ibm.com/developerworks/java/library/j-jml/index.html

public class A
{
    public /*@ pure @*/ int doA(int x)
    { ... }

    //@ requires ...
    //@ ensures doA(x) == doA(y)
    public int doB(int x, int y)
    { ... }
}
like image 172
helios35 Avatar answered Apr 24 '26 12:04

helios35



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!