vdm-vscode
vdm-vscode copied to clipboard
VDM++ indirections and invariants
This issue is somewhat similar to #197.
As part of an upcoming paper for OVT-21, ChessVDM, we were discussing some of the performance optimizations made in VDMJ related to VDM++ invariants and reference types. The question of whether indirections were also affected by the issue from #197 was raised.
Trying to test my hypothesis I found the bug in the snippet below.
Description:
-
A
is a class that holds some datax
. -
B
is a class with a reference to an instance ofA
. - C defines a type
BRule
that isB
with an invariant stating the valueB.a.x <> 42
. -
Runner
defines the test:- An instance
a
of typeA
is created withx := 1
. - An instance
b
of typeB
is created with a reference toa
- An instance
c
of typeC
is created with a reference tob
- The value for
a.x
is changed to 42 which is the illegal value for typeBRule
-
Expected behaviour: Specification fails since invariant for
BRule
is broken. - Actual behaviour: Specification does not fail
- An instance
class A
instance variables
public x : nat1;
operations
public A : nat1 ==> A
A(a) == x := a;
end A
class B
instance variables
public a : A;
operations
public B : A ==> B
B(a_arg) == a := a_arg;
end B
class C
instance variables
public b : BRule;
types
public BRule = B
inv b_arg == b_arg.a.x <> 42;
operations
public C : BRule ==> C
C(b_arg) == b := b_arg;
end C
class Runner
operations
public Run: () ==> ()
Run() ==
(
dcl a:A := new A(1);
dcl b:B := new B(a);
let c = new C(b) in
(
a.x := 42;
IO`print("C: ");
IO`print(c);
IO`print("\nNOTICE: Invariant for BRule broken.\n");
);
)
end Runner