summaryrefslogtreecommitdiffstats
path: root/testsuite/tests/typing-warnings/records.ml.reference
blob: 2853439c6567e5fc30f7fd181911356f7a2dc9ad (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

#         module M1 :
  sig type t = { x : int; y : int; } type u = { x : bool; y : bool; } end
#                 Characters 49-50:
    let f1 (r:t) = r.x (* ok *)
                     ^
Warning 42: this use of x required disambiguation.
Characters 89-90:
    let f2 r = ignore (r:t); r.x (* non principal *)
                               ^
Warning 42: this use of x required disambiguation.
Characters 148-149:
      match r with {x; y} -> y + y (* ok *)
                    ^
Warning 42: this use of x required disambiguation.
Characters 151-152:
      match r with {x; y} -> y + y (* ok *)
                       ^
Warning 42: this use of y required disambiguation.
Characters 148-149:
      match r with {x; y} -> y + y (* ok *)
                    ^
Warning 27: unused variable x.
module OK :
  sig val f1 : M1.t -> int val f2 : M1.t -> int val f3 : M1.t -> int end
#         Characters 55-61:
    let f r = match r with {x; y} -> y + y
                           ^^^^^^
Warning 41: these field labels belong to several types: M1.u M1.t
The first one was selected. Please disambiguate if this is wrong.
Characters 65-66:
    let f r = match r with {x; y} -> y + y
                                     ^
Error: This expression has type bool but an expression was expected of type
         int
#               Characters 86-87:
         {x; y} -> y + y
          ^
Warning 42: this use of x required disambiguation.
Characters 89-90:
         {x; y} -> y + y
             ^
Warning 42: this use of y required disambiguation.
Characters 86-87:
         {x; y} -> y + y
          ^
Warning 27: unused variable x.
module F2 : sig val f : M1.t -> int end
#           module M : sig type t = { x : int; } type u = { x : bool; } end
# Characters 18-21:
  let f (r:M.t) = r.M.x;; (* ok *)
                    ^^^
Warning 42: this use of x required disambiguation.
val f : M.t -> int = <fun>
# Characters 18-19:
  let f (r:M.t) = r.x;; (* warning *)
                    ^
Warning 40: x was selected from type M.t.
It is not visible in the current scope, and will not 
be selected if the type becomes unknown.
Characters 18-19:
  let f (r:M.t) = r.x;; (* warning *)
                    ^
Warning 42: this use of x required disambiguation.
val f : M.t -> int = <fun>
# Characters 8-9:
  let f ({x}:M.t) = x;; (* warning *)
          ^
Warning 42: this use of x required disambiguation.
Characters 7-10:
  let f ({x}:M.t) = x;; (* warning *)
         ^^^
Warning 40: this record of type M.t contains fields that are 
not visible in the current scope: x.
They will not be selected if the type becomes unknown.
val f : M.t -> int = <fun>
#       module M : sig type t = { x : int; y : int; } end
#     module N : sig type u = { x : bool; y : bool; } end
#         Characters 57-58:
    let f (r:M.t) = r.x
                      ^
Warning 42: this use of x required disambiguation.
Characters 30-36:
    open N
    ^^^^^^
Warning 33: unused open N.
module OK : sig val f : M.t -> int end
#           module M :
  sig
    type t = { x : int; }
    module N : sig type s = t = { x : int; } end
    type u = { x : bool; }
  end
#       module OK : sig val f : M.t -> int end
#           module M :
  sig
    type u = { x : bool; y : int; z : char; }
    type t = { x : int; y : bool; }
  end
#       Characters 37-38:
    let f {x;z} = x,z
           ^
Warning 42: this use of x required disambiguation.
Characters 36-41:
    let f {x;z} = x,z
          ^^^^^
Warning 9: the following labels are not bound in this record pattern:
y
Either bind these labels explicitly or add '; _' to the pattern.
module OK : sig val f : M.u -> bool * char end
#       Characters 38-52:
    let r = {x=true;z='z'}
            ^^^^^^^^^^^^^^
Error: Some record fields are undefined: y
#           Characters 90-91:
    let r = {x=3; y=true}
             ^
Warning 42: this use of x required disambiguation.
Characters 95-96:
    let r = {x=3; y=true}
                  ^
Warning 42: this use of y required disambiguation.
module OK :
  sig
    type u = { x : int; y : bool; }
    type t = { x : bool; y : int; z : char; }
    val r : u
  end
#               Characters 111-112:
    let b : bar = {x=3; y=4}
                        ^
Error: This record expression is expected to have type bar
       The field y does not belong to type bar
#   module M : sig type foo = { x : int; y : int; } end
# module N : sig type bar = { x : int; y : int; } end
# Characters 19-22:
  let r = { M.x = 3; N.y = 4; };; (* error: different definitions *)
                     ^^^
Error: The record field N.y belongs to the type N.bar
       but is mixed here with fields of type M.foo
#     module MN :
  sig
    type foo = M.foo = { x : int; y : int; }
    type bar = N.bar = { x : int; y : int; }
  end
module NM :
  sig
    type bar = N.bar = { x : int; y : int; }
    type foo = M.foo = { x : int; y : int; }
  end
# Characters 8-28:
  let r = {MN.x = 3; NM.y = 4};; (* error: type would change with order *)
          ^^^^^^^^^^^^^^^^^^^^
Warning 41: x belongs to several types: MN.bar MN.foo
The first one was selected. Please disambiguate if this is wrong.
Characters 8-28:
  let r = {MN.x = 3; NM.y = 4};; (* error: type would change with order *)
          ^^^^^^^^^^^^^^^^^^^^
Warning 41: y belongs to several types: NM.foo NM.bar
The first one was selected. Please disambiguate if this is wrong.
Characters 19-23:
  let r = {MN.x = 3; NM.y = 4};; (* error: type would change with order *)
                     ^^^^
Error: The record field NM.y belongs to the type NM.foo = M.foo
       but is mixed here with fields of type MN.bar = N.bar
#             module M :
  sig
    type foo = { x : int; y : int; }
    type bar = { x : int; y : int; z : int; }
  end
#       Characters 65-66:
    let f r = ignore (r: foo); {r with x = 2; z = 3}
                                       ^
Warning 42: this use of x required disambiguation.
Characters 72-73:
    let f r = ignore (r: foo); {r with x = 2; z = 3}
                                              ^
Error: This record expression is expected to have type M.foo
       The field z does not belong to type M.foo
#       module M :
  sig
    type foo = M.foo = { x : int; y : int; }
    type bar = M.bar = { x : int; y : int; z : int; }
    type other = { a : int; b : int; }
  end
#       Characters 66-67:
    let f r = ignore (r: foo); { r with x = 3; a = 4 }
                                        ^
Warning 42: this use of x required disambiguation.
Characters 73-74:
    let f r = ignore (r: foo); { r with x = 3; a = 4 }
                                               ^
Error: This record expression is expected to have type M.foo
       The field a does not belong to type M.foo
#         Characters 39-40:
    let r = {x=1; y=2}
             ^
Warning 42: this use of x required disambiguation.
Characters 44-45:
    let r = {x=1; y=2}
                  ^
Warning 42: this use of y required disambiguation.
Characters 67-68:
    let r: other = {x=1; y=2}
                    ^
Error: This record expression is expected to have type M.other
       The field x does not belong to type M.other
#     module A : sig type t = { x : int; } end
module B : sig type t = { x : int; } end
# Characters 20-23:
  let f (r : B.t) = r.A.x;; (* fail *)
                      ^^^
Error: The field A.x belongs to the record type A.t
       but a field was expected belonging to the record type B.t
#             Characters 88-91:
    let a : t = {x=1;yyz=2}
                     ^^^
Error: This record expression is expected to have type t
       The field yyz does not belong to type t
Hint: Did you mean yyy?
#             type t = A
type s = A
class f : t -> object  end
# Characters 12-13:
  class g = f A;; (* ok *)
              ^
Warning 42: this use of A required disambiguation.
class g : f
#   class f : 'a -> 'a -> object  end
# Characters 13-14:
  class g = f (A : t) A;; (* warn with -principal *)
               ^
Warning 42: this use of A required disambiguation.
Characters 20-21:
  class g = f (A : t) A;; (* warn with -principal *)
                      ^
Warning 42: this use of A required disambiguation.
class g : f
#                       Characters 199-200:
    let y : t = {x = 0}
                 ^
Warning 42: this use of x required disambiguation.
Characters 114-120:
    open M  (* this open is unused, it isn't reported as shadowing 'x' *)
    ^^^^^^
Warning 33: unused open M.
module Shadow1 :
  sig
    type t = { x : int; }
    module M : sig type s = { x : string; } end
    val y : t
  end
#               Characters 97-103:
    open M  (* this open shadows label 'x' *)
    ^^^^^^
Warning 45: this open statement shadows the label x (which is later used)
Characters 149-157:
    let y = {x = ""}
            ^^^^^^^^
Warning 41: these field labels belong to several types: M.s t
The first one was selected. Please disambiguate if this is wrong.
module Shadow2 :
  sig
    type t = { x : int; }
    module M : sig type s = { x : string; } end
    val y : M.s
  end
#                 Characters 167-170:
    let f (u : u) = match u with `Key {loc} -> loc
                                       ^^^
Warning 42: this use of loc required disambiguation.
module P6235 :
  sig
    type t = { loc : string; }
    type v = { loc : string; x : int; }
    type u = [ `Key of t ]
    val f : u -> string
  end
#                     Characters 220-223:
      |`Key {loc} -> loc
             ^^^
Warning 42: this use of loc required disambiguation.
module P6235' :
  sig
    type t = { loc : string; }
    type v = { loc : string; x : int; }
    type u = [ `Key of t ]
    val f : u -> string
  end
#