summaryrefslogtreecommitdiff
path: root/Test/dafny0/DiamondImports.dfy
blob: 1292211fa0bc14b7a785afb85f909ee66dac1512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// RUN: %dafny /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

module ImportByName {
  module A {
    type T
    function method P(): T
    method M(t: T)
  }

  module B {
    import A
  }

  module C {
    import A
    type K = A.T
    import W_A = W_B
    import W_B = A
  }

  module D {
    import B
    import C

    method Client() returns (t: B.A.T, u: C.A.T) {
      t := u;
      u := t;
      var x, y := B.A.P(), C.A.P();
      assert x == y;
      C.A.M(t);
      B.A.M(u);
      var anything;
      assert t == anything;  // error: (testing that it's not possible to prove false here)
    }
  }

  module E {
    import A
    import B
    import C
    method Client() returns (r: A.T, k: C.K) {
      var x, y, z := B.A.P(), C.A.P(), A.P();
      assert x == z == y;
      r, r, r := x, y, z;
      k, k, k, k := x, y, z, r;
      assert r == C.W_A.P();
      assert r == C.W_B.P();
      var anything;
      assert r == anything;  // error: (testing that it's not possible to prove false here)
    }
  }
}

// ------------------------------------------------------------

module ImportOpened {
  module A {
    type T
    function method P(): T
    method M(t: T)
  }

  module B {
    import opened A
  }

  module C {
    import opened A
    type K = T
    type L = A.T  // should work when name is qualified, too
    import W_A = W_B
    import W_B = A
  }

  module C' {
    import A  // import by name
    type K = A.T
  }

  module D {
    import opened B
    import opened C
    import opened C'

    method Client() returns (t: B.A.T, u: C.A.T, v: C'.A.T, w: B.T) {
      t,u, v, w := u, v, w, t;
      var x, y, z := B.A.P(), C.A.P(), C'.A.P();
      assert x == y == z;
      var o;
      x, y, z, o := B.P(), C.P(), C'.A.P(), A.P();
      assert x == y == z == o;

      B.A.M(u);
      C.A.M(t);
      C'.A.M(t);
      B.M(t);
      C.M(t);
      M(t);
      var anything;
      assert t == anything;  // error: (testing that it's not possible to prove false here)
    }
  }

  module E {
    import opened A
    import opened B
    import opened C
    method Client() returns (r: A.T, k: C.K, l: C.L, m: K, n: L) {
      var x, y, z := B.A.P(), C.A.P(), A.P();
      assert x == z == y;
      r, r, r := x, y, z;
      k, k, k, k := x, y, z, r;
      l, l, l, l, l := x, y, z, r, k;
      m, n := k, l;
      assert m == n == k;
      assert r == C.W_A.P() == C.W_B.P();
      assert r == W_A.P() == W_B.P();
      var anything;
      assert r == anything;  // error: (testing that it's not possible to prove false here)
    }
  }
}

module AmbiguousModuleReference {
  module A {
    module Inner {
      predicate Q()
    }
  }
  module B {
    module Inner {
      predicate Q()
    }
  }
  module Client {
    import A
    import B
    method M() {
      assert A.Inner.Q() <==> B.Inner.Q();  // error: no reason to think these would be equal
    }
  }
}