Considering the following example of a simple Record with a compact constructor:
public record Point2dU(int x, int y) {
Point2dU {
if(x<0) x *= -1;
if(y<0) y *= -1;
}
}
by conversion it is similar to
public class Point2dU {
private final int x; private final int y;
public Point2dU((int x, int y) {
if(x<0) x *= -1;
if(y<0) y *= -1;
this.x = x; this.y = y;
}
...
}
Now, the constructor behavior is modified by the compact constructor code.
How can I describe the synthetic constructor behavior?
The recent version of JmlRef does not cover this.
Questions
Where should the contract be?
-
On the record
/*@ ensures this.x>0 && this.y>0; */
record Point2d(int x, int y) { ... }
-
On the compact constructor
record Point2d(int x, int y) {
/*@ ensures this.x>0 && this.y>0; */
Point2d { ... }
}
When a contract is given, should the synthetic contract (e.g., ensures this.x == x ...;) still be injected?
Considering the following example of a simple Record with a compact constructor:
by conversion it is similar to
Now, the constructor behavior is modified by the compact constructor code.
How can I describe the synthetic constructor behavior?
The recent version of JmlRef does not cover this.
Questions
Where should the contract be?
On the record
On the compact constructor
When a contract is given, should the synthetic contract (e.g.,
ensures this.x == x ...;) still be injected?