summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-misc/wrong_kind.ml
blob: 76d1a07688a678c7513cb7ece89e8c0cfc734b7e (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
(* TEST
   * expect
*)

module Constr = struct
  type t = A | B | C

  let get _ _ = A

  let put f = ignore (f () : t)
end

module Record = struct
  type t = { a : int; b : int; c : int }

  let get _ _ = { a = 0; b = 0; c = 0 }

  let put f = ignore (f () : t)
end

module Bool = struct
  type t = true | false

  let get _ _ = true

  let put f = ignore (f () : t)
end

module List = struct
  type 'a t = [] | (::) of 'a * 'a t

  let get _ _ = []

  let put f = ignore (f () : int t)
end

module Unit = struct
  [@@@warning "-redefining-unit"]
  type t = ()

  let get _ _ = ()

  let put f = ignore (f (() : unit) : t)
end;;
[%%expect{|
module Constr :
  sig
    type t = A | B | C
    val get : 'a -> 'b -> t
    val put : (unit -> t) -> unit
  end
module Record :
  sig
    type t = { a : int; b : int; c : int; }
    val get : 'a -> 'b -> t
    val put : (unit -> t) -> unit
  end
module Bool :
  sig
    type t = true | false
    val get : 'a -> 'b -> t
    val put : (unit -> t) -> unit
  end
module List :
  sig
    type 'a t = [] | (::) of 'a * 'a t
    val get : 'a -> 'b -> 'c t
    val put : (unit -> int t) -> unit
  end
module Unit :
  sig type t = () val get : 'a -> 'b -> t val put : (unit -> t) -> unit end
|}]

let () =
  match Constr.get () with
  | A | B | C -> ();;
[%%expect{|
Line 3, characters 4-5:
3 |   | A | B | C -> ();;
        ^
Error: This pattern should not be a constructor, the expected type is
       'a -> Constr.t
|}]

let () =
  match Record.get () with
  | { a; _ } -> ();;
[%%expect{|
Line 3, characters 4-12:
3 |   | { a; _ } -> ();;
        ^^^^^^^^
Error: This pattern should not be a record, the expected type is
       'a -> Record.t
|}]

let () =
  match Bool.get () with
  | true -> ();;
[%%expect{|
Line 3, characters 4-8:
3 |   | true -> ();;
        ^^^^
Error: This pattern should not be a boolean literal, the expected type is
       'a -> Bool.t
|}]

let () =
  match Bool.get () with
  | false -> ();;
[%%expect{|
Line 3, characters 4-9:
3 |   | false -> ();;
        ^^^^^
Error: This pattern should not be a boolean literal, the expected type is
       'a -> Bool.t
|}]

let () =
  match List.get () with
  | [] -> ();;
[%%expect{|
Line 3, characters 4-6:
3 |   | [] -> ();;
        ^^
Error: This pattern should not be a list literal, the expected type is
       'a -> 'b List.t
|}]

let () =
  match List.get () with
  | _ :: _ -> ();;
[%%expect{|
Line 3, characters 4-10:
3 |   | _ :: _ -> ();;
        ^^^^^^
Error: This pattern should not be a list literal, the expected type is
       'a -> 'b List.t
|}]

let () =
  match Unit.get () with
  | () -> ();;
[%%expect{|
Line 3, characters 4-6:
3 |   | () -> ();;
        ^^
Error: This pattern should not be a unit literal, the expected type is
       'a -> Unit.t
|}]

let () = Constr.put A;;
[%%expect{|
Line 1, characters 20-21:
1 | let () = Constr.put A;;
                        ^
Error: This expression should not be a constructor, the expected type is
       unit -> Constr.t
|}]

let () = Record.put { a = 0; b = 0; c = 0 };;
[%%expect{|
Line 1, characters 20-43:
1 | let () = Record.put { a = 0; b = 0; c = 0 };;
                        ^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression should not be a record, the expected type is
       unit -> Record.t
|}]

let () = Bool.put true;;
[%%expect{|
Line 1, characters 18-22:
1 | let () = Bool.put true;;
                      ^^^^
Error: This expression should not be a boolean literal, the expected type is
       unit -> Bool.t
|}]

let () = Bool.put false;;
[%%expect{|
Line 1, characters 18-23:
1 | let () = Bool.put false;;
                      ^^^^^
Error: This expression should not be a boolean literal, the expected type is
       unit -> Bool.t
|}]

let () = List.put [];;
[%%expect{|
Line 1, characters 18-20:
1 | let () = List.put [];;
                      ^^
Error: This expression should not be a list literal, the expected type is
       unit -> int List.t
|}]

let () = List.put (1 :: 2);;
[%%expect{|
Line 1, characters 18-26:
1 | let () = List.put (1 :: 2);;
                      ^^^^^^^^
Error: This expression should not be a list literal, the expected type is
       unit -> int List.t
|}]

let () = Unit.put ();;
[%%expect{|
Line 1, characters 18-20:
1 | let () = Unit.put ();;
                      ^^
Error: This expression should not be a unit literal, the expected type is
       unit -> Unit.t
|}]

let () =
  ignore ((Record.get ()).a);;
[%%expect{|
Line 2, characters 10-25:
2 |   ignore ((Record.get ()).a);;
              ^^^^^^^^^^^^^^^
Error: This expression has type 'a -> Record.t which is not a record type.
|}]

let () =
  (Record.get ()).a <- 5;;
[%%expect{|
Line 2, characters 2-17:
2 |   (Record.get ()).a <- 5;;
      ^^^^^^^^^^^^^^^
Error: This expression has type 'a -> Record.t which is not a record type.
|}]

let () =
  ignore { (Record.get ()) with a = 5 };;
[%%expect{|
Line 2, characters 11-26:
2 |   ignore { (Record.get ()) with a = 5 };;
               ^^^^^^^^^^^^^^^
Error: This expression has type 'a -> Record.t which is not a record type.
|}]

let foo x =
  Record.put { x with a = 5 };;
[%%expect{|
Line 2, characters 13-29:
2 |   Record.put { x with a = 5 };;
                 ^^^^^^^^^^^^^^^^
Error: This expression should not be a record, the expected type is
       unit -> Record.t
|}]