summaryrefslogtreecommitdiff
path: root/Test/dafny0/DatatypeUpdate.dfy
blob: 09f07dd36416f2a9543c30124076169a2ad24816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

datatype MyDataType = MyConstructor(myint:int, mybool:bool) 
                    | MyOtherConstructor(otherbool:bool) 
                    | MyNumericConstructor(42:int);

method test(foo:MyDataType, x:int) returns (abc:MyDataType, def:MyDataType, ghi:MyDataType, jkl:MyDataType)
    requires foo.MyConstructor?;
    ensures abc == foo[myint := x + 2];
    ensures def == foo[otherbool := !foo.mybool];
    ensures ghi == foo[myint := 2][mybool := false];
    //ensures jkl == foo[non_destructor := 5];      // Resolution error: no non_destructor in MyDataType
    ensures jkl == foo[42 := 7];
{
    abc := MyConstructor(x + 2, foo.mybool); 
    abc := foo[myint := x + 2];
    def := MyOtherConstructor(!foo.mybool);
    ghi := MyConstructor(2, false);
    jkl := foo[42 := 7];

    assert abc[myint := abc.myint - 2] == foo[myint := x];
}