Debian Codegraph @

test/errors.mlt

raw
1 type t = { a : int [@sexp_drop_default] [@sexp.omit_nil] } [@@deriving sexp_of]
2
3 [%%expect
4 {|
5 Line _, characters _-_:
6 Error: The following elements are mutually exclusive: sexp.sexp_drop_default sexp.omit_nil
7 |}]
8
9 type t = { a : int list [@sexp.list] [@sexp.omit_nil] } [@@deriving sexp_of]
10
11 [%%expect
12 {|
13 Line _, characters _-_:
14 Error: The following elements are mutually exclusive: sexp.omit_nil [@sexp.list]
15 |}]
16
17 type t = { a : int [@default 0] [@sexp.omit_nil] } [@@deriving of_sexp]
18
19 [%%expect
20 {|
21 Line _, characters _-_:
22 Error: The following elements are mutually exclusive: sexp.default sexp.omit_nil
23 |}]
24
25 type t = int [@@deriving sexp] [@@sexp.allow_extra_fields]
26
27 [%%expect
28 {|
29 Line _, characters _-_:
30 Error: ppx_sexp_conv: [@@allow_extra_fields] is only allowed on records.
31 |}]
32
33 type 'a t = 'a option =
34 | None
35 | Some of 'a
36 [@@deriving sexp] [@@sexp.allow_extra_fields]
37
38 [%%expect
39 {|
40 Line _, characters _-_:
41 Error: ppx_sexp_conv: [@@allow_extra_fields] is only allowed on records.
42 |}]
43
44 type 'a t = Some of { a : int } [@@deriving sexp] [@@sexp.allow_extra_fields]
45
46 [%%expect
47 {|
48 Line _, characters _-_:
49 Error: ppx_sexp_conv: [@@allow_extra_fields] only works on records. For inline records, do: type t = A of { a : int } [@allow_extra_fields] | B [@@deriving sexp]
50 |}]
51
52 type 'a t =
53 | Some of { a : int }
54 | None [@sexp.allow_extra_fields]
55 [@@deriving sexp]
56
57 [%%expect
58 {|
59 Line _, characters _-_:
60 Error: ppx_sexp_conv: [@allow_extra_fields] is only allowed on inline records.
61 |}]
62
63 type t =
64 | Non
65 | Som of { next : t [@default Non] [@sexp_drop_default.equal] }
66 [@@deriving sexp]
67
68 [%%expect
69 {|
70 Line _, characters _-_:
71 Error: [@sexp_drop_default.equal] was used, but the type of the field contains a type defined in the current recursive block: t.
72 This is not supported.
73 Consider using [@sexp_drop_if _] or [@sexp_drop_default.sexp] instead.
74 |}]
75
76 type nonrec 'a t = { foo : 'a option [@default None] [@sexp_drop_default.equal] }
77 [@@deriving sexp]
78
79 [%%expect
80 {|
81 Line _, characters _-_:
82 Error: [@sexp_drop_default.equal] was used, but the type of the field contains a type variable: 'a.
83 Comparison is not avaiable for type variables.
84 Consider using [@sexp_drop_if _] or [@sexp_drop_default.sexp] instead.
85 |}]
86
87 open Base
88
89 type t = { a : int [@default 8] [@sexp_drop_default] } [@@deriving sexp_of]
90
91 [%%expect
92 {|
93 Line _, characters _-_:
94 Error (warning 22 [preprocessor]): [@sexp_drop_default] is deprecated: please use one of:
95 - [@sexp_drop_default f] and give an explicit equality function ([f = Poly.(=)] corresponds to the old behavior)
96 - [@sexp_drop_default.compare] if the type supports [%compare]
97 - [@sexp_drop_default.equal] if the type supports [%equal]
98 - [@sexp_drop_default.sexp] if you want to compare the sexp representations
99 |}]
100
101 type t = { x : unit [@sexp.opaque] } [@@deriving sexp_of]
102 type t = { x : unit [@sexp.opaque] } [@@deriving of_sexp]
103 type t = { x : unit [@sexp.opaque] } [@@deriving sexp_grammar]
104
105 [%%expect
106 {|
107 Line _, characters _-_:
108 Error: Attribute `sexp.opaque' was not used.
109 Hint: `sexp.opaque' is available for core types but is used here in
110 the
111 context of a label declaration.
112 Did you put it at the wrong level?
113
114 Line _, characters _-_:
115 Error: Attribute `sexp.opaque' was not used.
116 Hint: `sexp.opaque' is available for core types but is used here in
117 the
118 context of a label declaration.
119 Did you put it at the wrong level?
120
121 Line _, characters _-_:
122 Error: Attribute `sexp.opaque' was not used.
123 Hint: `sexp.opaque' is available for core types but is used here in
124 the
125 context of a label declaration.
126 Did you put it at the wrong level?
127 |}]
128
129 type t = { x : unit [@sexp.option] } [@@deriving sexp_of]
130 type t = { x : unit [@sexp.option] } [@@deriving of_sexp]
131 type t = { x : unit [@sexp.option] } [@@deriving sexp_grammar]
132
133 [%%expect
134 {|
135 Line _, characters _-_:
136 Error: ppx_sexp_conv: [@sexp.option] is only allowed on type [_ option].
137
138 Line _, characters _-_:
139 Error: ppx_sexp_conv: [@sexp.option] is only allowed on type [_ option].
140
141 Line _, characters _-_:
142 Error: ppx_sexp_conv: [@sexp.option] is only allowed on type [_ option].
143 |}]
144
145 type t = { x : unit [@sexp.list] } [@@deriving sexp_of]
146 type t = { x : unit [@sexp.list] } [@@deriving of_sexp]
147 type t = { x : unit [@sexp.list] } [@@deriving sexp_grammar]
148
149 [%%expect
150 {|
151 Line _, characters _-_:
152 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
153
154 Line _, characters _-_:
155 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
156
157 Line _, characters _-_:
158 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
159 |}]
160
161 type t = { x : unit [@sexp.array] } [@@deriving sexp_of]
162 type t = { x : unit [@sexp.array] } [@@deriving of_sexp]
163 type t = { x : unit [@sexp.array] } [@@deriving sexp_grammar]
164
165 [%%expect
166 {|
167 Line _, characters _-_:
168 Error: ppx_sexp_conv: [@sexp.array] is only allowed on type [_ array].
169
170 Line _, characters _-_:
171 Error: ppx_sexp_conv: [@sexp.array] is only allowed on type [_ array].
172
173 Line _, characters _-_:
174 Error: ppx_sexp_conv: [@sexp.array] is only allowed on type [_ array].
175 |}]
176
177 type t = { x : unit [@sexp.bool] } [@@deriving sexp_of]
178 type t = { x : unit [@sexp.bool] } [@@deriving of_sexp]
179 type t = { x : unit [@sexp.bool] } [@@deriving sexp_grammar]
180
181 [%%expect
182 {|
183 Line _, characters _-_:
184 Error: ppx_sexp_conv: [@sexp.bool] is only allowed on type [bool].
185
186 Line _, characters _-_:
187 Error: ppx_sexp_conv: [@sexp.bool] is only allowed on type [bool].
188
189 Line _, characters _-_:
190 Error: ppx_sexp_conv: [@sexp.bool] is only allowed on type [bool].
191 |}]
192
193 type t = A of unit [@sexp.list] [@@deriving sexp_of]
194 type t = A of unit [@sexp.list] [@@deriving of_sexp]
195 type t = A of unit [@sexp.list] [@@deriving sexp_grammar]
196
197 [%%expect
198 {|
199 Line _, characters _-_:
200 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
201
202 Line _, characters _-_:
203 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
204
205 Line _, characters _-_:
206 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
207 |}]
208
209 type t = [ `A of unit [@sexp.list] ] [@@deriving sexp_of]
210 type t = [ `A of unit [@sexp.list] ] [@@deriving of_sexp]
211 type t = [ `A of unit [@sexp.list] ] [@@deriving sexp_grammar]
212
213 [%%expect
214 {|
215 Line _, characters _-_:
216 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
217
218 Line _, characters _-_:
219 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
220
221 Line _, characters _-_:
222 Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
223 |}]
224
225 let (_ : _) = [%sexp_grammar: 'k -> 'v -> ('k * 'v) list]
226
227 [%%expect {| |}]
228
229 let (_ : _) = [%sexp_grammar: < for_all : 'k 'v. ('k * 'v) list > ]
230
231 [%%expect
232 {|
233 Line _, characters _-_:
234 Error: sexp_grammar: object types are unsupported
235 |}]
236
237 let (_ : _) = [%sexp_grammar: < other : 'k 'v. ('k * 'v) list > ]
238
239 [%%expect
240 {|
241 Line _, characters _-_:
242 Error: sexp_grammar: object types are unsupported
243 |}]
244
245 type t = < for_all : 'k 'v. ('k * 'v) list > [@@deriving sexp_grammar]
246
247 [%%expect
248 {|
249 Line _, characters _-_:
250 Error: sexp_grammar: object types are unsupported
251 |}]
252
253 type t = < other : 'k 'v. ('k * 'v) list > [@@deriving sexp_grammar]
254
255 [%%expect
256 {|
257 Line _, characters _-_:
258 Error: sexp_grammar: object types are unsupported
259 |}]
260
261 type t = T : 'a -> t [@@deriving sexp_grammar]
262
263 [%%expect
264 {|
265 Line _, characters _-_:
266 Error: Unbound value _'a_sexp_grammar
267 Hint: Did you mean char_sexp_grammar, int_sexp_grammar or ref_sexp_grammar?
268 |}]
269
270 (* If we can sensibly derive [sexp_grammar], we might as well, because the user might
271 still be able to pair it with a consistent hand-written [t_of_sexp]. *)
272 type _ t = T : int -> string t [@@deriving sexp_grammar]
273
274 [%%expect {| |}]
275
276 type _ t = T : int -> string t [@@deriving of_sexp]
277
278 [%%expect
279 {|
280 Line _, characters _-_:
281 Error: This expression has type string t
282 but an expression was expected of type a__098_ t
283 Type string is not compatible with type a__098_
284 |}]