Skip to content

Compact constructors and JML #62

Description

@wadoon

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?

  1. On the record

    /*@ ensures this.x>0 && this.y>0; */
    record Point2d(int x, int y) { ... } 
    
  2. 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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions