1

I've recently read the following JML code in an old exam:

Class L {
  /*@non_null*/ int[] a;

  /*@ public normal_behaviour
    @ requires !(\exists int i; 0 <= i && i < a.length; a[i] == d);
    @ ensures a.length == \old(a.length) + 1;
    @ ensures a[\old(a.length)] == d;
    @ ensures (\forall int i; 0 <= i && i < \old(a.length);
                  a[i] == \old(a[i]));
    @ assignable a, a[*];
    @*/
  public void st(int d) {
      ...
  }
}

I don't understand the

assignable a, a[*];

part. What does a[*] mean? What would be different if there was only

assignable a;

?

(A link to a reference would be great.)

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958

1 Answers1

1

The assignable clause in JML only allows a method to modify a location loc if:

- loc is mentioned in the method’s assignable clause;
- loc is not allocated when the method starts execution; or
- loc is local to the method (i.e., a local variable or a formal parameter)

The use of a[*] is shorthand for [0 ... a.length-1];¹

More Information | Cited Reference

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • Just to clarify: "assignable a, a[*]" means that you both may do "a = new int[0];" and "a[17] = 42", whereas by omitting one sub-clause the respective statement would be illegal. I'd vote for choosing that answer as the right one, by the way. – dsteinhoefel Oct 10 '17 at 09:30