File: errors.mlt

package info (click to toggle)
ppx-yojson-conv 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 360 kB
  • sloc: ml: 3,498; makefile: 14
file content (163 lines) | stat: -rw-r--r-- 4,146 bytes parent folder | download | duplicates (2)
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
open Base_yojson

type t = int [@@deriving yojson] [@@yojson.allow_extra_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: [@@allow_extra_fields] is only allowed on records.
|}]

type 'a t = 'a option =
  | None
  | Some of 'a
[@@deriving yojson] [@@yojson.allow_extra_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: [@@allow_extra_fields] is only allowed on records.
|}]

type 'a t = Some of { a : int } [@@deriving yojson] [@@yojson.allow_extra_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: [@@allow_extra_fields] only works on records. For inline records, do: type t = A of { a : int } [@allow_extra_fields] | B [@@deriving yojson]
|}]

type 'a t =
  | Some of { a : int }
  | None [@yojson.allow_extra_fields]
[@@deriving yojson]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: [@allow_extra_fields] is only allowed on inline records.
|}]

type t =
  | Non
  | Som of { next : t [@default Non] [@yojson_drop_default.equal] }
[@@deriving yojson]

[%%expect
  {|
Line _, characters _-_:
Error: [@yojson_drop_default.equal] was used, but the type of the field contains a type defined in the current recursive block: t.
This is not supported.
Consider using [@yojson_drop_if _] or [@yojson_drop_default.yojson] instead.
|}]

type nonrec 'a t = { foo : 'a option [@default None] [@yojson_drop_default.equal] }
[@@deriving yojson]

[%%expect
  {|
Line _, characters _-_:
Error: [@yojson_drop_default.equal] was used, but the type of the field contains a type variable: 'a.
Comparison is not avaiable for type variables.
Consider using [@yojson_drop_if _] or [@yojson_drop_default.yojson] instead.
|}]

open Base

type t = { a : int [@default 8] [@yojson_drop_default] } [@@deriving yojson_of]

[%%expect
  {|
Line _, characters _-_:
Error (warning 22 [preprocessor]): [@yojson_drop_default] is deprecated: please use one of:
- [@yojson_drop_default f] and give an explicit equality function ([f = Poly.(=)] corresponds to the old behavior)
- [@yojson_drop_default.compare] if the type supports [%compare]
- [@yojson_drop_default.equal] if the type supports [%equal]
- [@yojson_drop_default.yojson] if you want to compare the yojson representations
|}]

type t = { x : unit [@yojson.opaque] } [@@deriving yojson_of]
type t = { x : unit [@yojson.opaque] } [@@deriving of_yojson]

[%%expect
  {|
Line _, characters _-_:
Error: Attribute `yojson.opaque' was not used.
       Hint: `yojson.opaque' is available for core types but is used here in
       the
       context of a label declaration.
       Did you put it at the wrong level?

Line _, characters _-_:
Error: Attribute `yojson.opaque' was not used.
       Hint: `yojson.opaque' is available for core types but is used here in
       the
       context of a label declaration.
       Did you put it at the wrong level?
|}]

type t = { x : unit [@yojson.option] } [@@deriving yojson_of]
type t = { x : unit [@yojson.option] } [@@deriving of_yojson]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: [@yojson.option] is only allowed on type [_ option].

Line _, characters _-_:
Error: ppx_yojson_conv: [@yojson.option] is only allowed on type [_ option].
|}]

type t = int [@@deriving yojson_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: yojson_fields only works on records
|}]

type t = A [@@deriving yojson_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: yojson_fields only works on records
|}]

type t =
  [ `A
  | `B
  ]
[@@deriving yojson_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: yojson_fields only works on records
|}]

type t = int * int [@@deriving yojson_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: yojson_fields only works on records
|}]

type t = { x : u }
and vvv = int
and u = { y : t } [@@deriving yojson_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: yojson_fields only works on records
|}]

type t = string list [@@deriving yojson_fields]

[%%expect
  {|
Line _, characters _-_:
Error: ppx_yojson_conv: yojson_fields only works on records
|}]