Skip to content

Commit 1fa67ae

Browse files
committed
fix: explicit annotate custom scalar as Yojson.Basic.t for return type magic
1 parent 6dfbaec commit 1fa67ae

File tree

4 files changed

+91
-128
lines changed

4 files changed

+91
-128
lines changed

src/native/output_native_decoder.re

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ open Parsetree;
99
open Generator_utils;
1010
open Output_native_utils;
1111

12-
let const_str_expr = s =>
13-
Ast_helper.(Exp.constant([@implicit_arity] Pconst_string(s, None)));
12+
let const_str_expr = s => Ast_helper.(Exp.constant(Pconst_string(s, None)));
1413

1514
let make_error_raiser = message =>
1615
if (Ppx_config.verbose_error_handling()) {
@@ -82,7 +81,7 @@ let generate_poly_enum_decoder = (loc, enum_meta) => {
8281
List.map(
8382
({evm_name, _}) =>
8483
Exp.case(
85-
Pat.constant([@implicit_arity] Pconst_string(evm_name, None)),
84+
Pat.constant(Pconst_string(evm_name, None)),
8685
Exp.variant(evm_name, None),
8786
),
8887
enum_meta.em_values,
@@ -114,8 +113,7 @@ let generate_poly_enum_decoder = (loc, enum_meta) => {
114113
Ast_helper.(
115114
Typ.variant(
116115
List.map(
117-
({evm_name, _}) =>
118-
[@implicit_arity] Rtag({txt: evm_name, loc}, [], true, []),
116+
({evm_name, _}) => Rtag({txt: evm_name, loc}, [], true, []),
119117
enum_meta.em_values,
120118
),
121119
Closed,
@@ -154,53 +152,49 @@ let generate_error = (loc, message) => {
154152

155153
let rec generate_decoder = config =>
156154
fun
157-
| [@implicit_arity] Res_nullable(loc, inner) =>
155+
| Res_nullable(loc, inner) =>
158156
generate_nullable_decoder(config, conv_loc(loc), inner)
159-
| [@implicit_arity] Res_array(loc, inner) =>
157+
| Res_array(loc, inner) =>
160158
generate_array_decoder(config, conv_loc(loc), inner)
161159
| Res_id(loc) => id_decoder(conv_loc(loc))
162160
| Res_string(loc) => string_decoder(conv_loc(loc))
163161
| Res_int(loc) => int_decoder(conv_loc(loc))
164162
| Res_float(loc) => float_decoder(conv_loc(loc))
165163
| Res_boolean(loc) => boolean_decoder(conv_loc(loc))
166-
| Res_raw_scalar(_loc) => {
167-
%expr
168-
value;
169-
}
170-
| [@implicit_arity] Res_poly_enum(loc, enum_meta) =>
164+
| Res_raw_scalar(_loc) => [%expr value]
165+
| Res_poly_enum(loc, enum_meta) =>
171166
generate_poly_enum_decoder(conv_loc(loc), enum_meta)
172-
| [@implicit_arity] Res_custom_decoder(loc, ident, inner) =>
167+
| Res_custom_decoder(loc, ident, inner) =>
173168
generate_custom_decoder(config, conv_loc(loc), ident, inner)
174-
| [@implicit_arity] Res_record(loc, name, fields) =>
169+
| Res_record(loc, name, fields) =>
175170
generate_record_decoder(config, conv_loc(loc), name, fields)
176-
| [@implicit_arity] Res_object(loc, name, fields) =>
171+
| Res_object(loc, name, fields) =>
177172
generate_object_decoder(config, conv_loc(loc), name, fields)
178-
| [@implicit_arity] Res_poly_variant_selection_set(loc, name, fields) =>
173+
| Res_poly_variant_selection_set(loc, name, fields) =>
179174
generate_poly_variant_selection_set(config, conv_loc(loc), name, fields)
180-
| [@implicit_arity] Res_poly_variant_union(loc, name, fragments, exhaustive) =>
175+
| Res_poly_variant_union(loc, name, fragments, exhaustive) =>
181176
generate_poly_variant_union(
182177
config,
183178
conv_loc(loc),
184179
name,
185180
fragments,
186181
exhaustive,
187182
)
188-
| [@implicit_arity] Res_poly_variant_interface(loc, name, base, fragments) =>
183+
| Res_poly_variant_interface(loc, name, base, fragments) =>
189184
generate_poly_variant_interface(
190185
config,
191186
conv_loc(loc),
192187
name,
193188
base,
194189
fragments,
195190
)
196-
| [@implicit_arity] Res_solo_fragment_spread(loc, name) =>
191+
| Res_solo_fragment_spread(loc, name) =>
197192
generate_solo_fragment_spread(conv_loc(loc), name)
198-
| [@implicit_arity] Res_error(loc, message) =>
199-
generate_error(conv_loc(loc), message)
193+
| Res_error(loc, message) => generate_error(conv_loc(loc), message)
200194
and generate_nullable_decoder = (config, loc, inner) =>
201195
[@metaloc loc]
202196
(
203-
switch%expr (value) {
197+
switch%expr ((value: Yojson.Basic.t)) {
204198
| `Null => None
205199
| value => Some([%e generate_decoder(config, inner)])
206200
}
@@ -256,7 +250,7 @@ and generate_record_decoder = (config, loc, name, fields) => {
256250
fields
257251
|> filter_map(
258252
fun
259-
| [@implicit_arity] Fr_named_field(field, _, _) =>
253+
| Fr_named_field(field, _, _) =>
260254
Some(Pat.var({loc, txt: "field_" ++ field}))
261255
| Fr_fragment_spread(_) => None,
262256
)
@@ -268,7 +262,7 @@ and generate_record_decoder = (config, loc, name, fields) => {
268262
fields
269263
|> filter_map(
270264
fun
271-
| [@implicit_arity] Fr_named_field(field, loc, inner) => {
265+
| Fr_named_field(field, loc, inner) => {
272266
let loc = conv_loc(loc);
273267
[@metaloc loc]
274268
Some(
@@ -304,7 +298,7 @@ and generate_record_decoder = (config, loc, name, fields) => {
304298
fields
305299
|> List.map(
306300
fun
307-
| [@implicit_arity] Fr_named_field(field, loc, _) => {
301+
| Fr_named_field(field, loc, _) => {
308302
let loc = conv_loc(loc);
309303
(
310304
{Location.loc, txt: Longident.Lident(field)},
@@ -314,7 +308,7 @@ and generate_record_decoder = (config, loc, name, fields) => {
314308
),
315309
);
316310
}
317-
| [@implicit_arity] Fr_fragment_spread(field, loc, name) => {
311+
| Fr_fragment_spread(field, loc, name) => {
318312
let loc = conv_loc(loc);
319313
(
320314
{Location.loc, txt: Longident.Lident(field)},
@@ -359,11 +353,10 @@ and generate_object_decoder = (config, loc, name, fields) =>
359353
Pat.any(),
360354
List.map(
361355
fun
362-
| [@implicit_arity] Fr_named_field(key, _, inner) =>
356+
| Fr_named_field(key, _, inner) =>
363357
Cf.method(
364358
{txt: key, loc: Location.none},
365359
Public,
366-
[@implicit_arity]
367360
Cfk_concrete(
368361
Fresh,
369362
switch%expr (List.assoc([%e const_str_expr(key)], value)) {
@@ -388,12 +381,11 @@ and generate_object_decoder = (config, loc, name, fields) =>
388381
},
389382
),
390383
)
391-
| [@implicit_arity] Fr_fragment_spread(key, loc, name) => {
384+
| Fr_fragment_spread(key, loc, name) => {
392385
let loc = conv_loc(loc);
393386
Cf.method(
394387
{txt: key, loc: Location.none},
395388
Public,
396-
[@implicit_arity]
397389
Cfk_concrete(
398390
Fresh,
399391
{
@@ -462,7 +454,6 @@ and generate_poly_variant_selection_set = (config, loc, name, fields) => {
462454
Typ.variant(
463455
List.map(
464456
((name, _)) =>
465-
[@implicit_arity]
466457
Rtag(
467458
{txt: Compat.capitalize_ascii(name), loc},
468459
[],
@@ -506,14 +497,12 @@ and generate_poly_variant_interface = (config, loc, name, base, fragments) => {
506497

507498
let map_case = ((type_name, inner)) => {
508499
open Ast_helper;
509-
let name_pattern =
510-
Pat.constant([@implicit_arity] Pconst_string(type_name, None));
500+
let name_pattern = Pat.constant(Pconst_string(type_name, None));
511501
let variant =
512502
Exp.variant(type_name, Some(generate_decoder(config, inner)));
513503
Exp.case(name_pattern, variant);
514504
};
515505
let map_case_ty = ((name, _)) =>
516-
[@implicit_arity]
517506
Rtag(
518507
name,
519508
[],
@@ -589,8 +578,7 @@ and generate_poly_variant_union =
589578
Ast_helper.(
590579
fragments
591580
|> List.map(((type_name, inner)) => {
592-
let name_pattern =
593-
Pat.constant([@implicit_arity] Pconst_string(type_name, None));
581+
let name_pattern = Pat.constant(Pconst_string(type_name, None));
594582
let variant =
595583
Ast_helper.(
596584
Exp.variant(type_name, Some(generate_decoder(config, inner)))
@@ -617,16 +605,13 @@ and generate_poly_variant_union =
617605
)
618606
| Nonexhaustive => (
619607
Exp.case(Pat.any(), [%expr `Nonexhaustive]),
620-
[
621-
[@implicit_arity] Rtag({txt: "Nonexhaustive", loc}, [], true, []),
622-
],
608+
[Rtag({txt: "Nonexhaustive", loc}, [], true, [])],
623609
)
624610
}
625611
);
626612
let fragment_case_tys =
627613
List.map(
628614
((name, _)) =>
629-
[@implicit_arity]
630615
Rtag(
631616
{txt: name, loc},
632617
[],

src/native/output_native_encoder.re

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ let rec parser_for_type = (schema, loc, type_ref) => {
8484
(
8585
v =>
8686
switch (v) {
87-
| None => `Null
87+
| None => (`Null: Yojson.Basic.t)
8888
| Some(v) => [%e child_parser](v)
8989
}
9090
)
@@ -124,11 +124,7 @@ let json_of_fields = (schema, loc, expr, fields) => {
124124
[@metaloc loc]
125125
[%expr
126126
(
127-
[%e
128-
Ast_helper.Exp.constant(
129-
[@implicit_arity] Pconst_string(am_name, None),
130-
)
131-
],
127+
[%e Ast_helper.Exp.constant(Pconst_string(am_name, None))],
132128
[%e parser](
133129
[%e Ast_helper.Exp.send(expr, {txt: am_name, loc})],
134130
),
@@ -162,9 +158,7 @@ let generate_encoder = (config, (spanning, x)) => {
162158
|> List.map(({evm_name, _}) => {
163159
let pattern = Ast_helper.Pat.variant(evm_name, None);
164160
let expr =
165-
Ast_helper.Exp.constant(
166-
[@implicit_arity] Pconst_string(evm_name, None),
167-
);
161+
Ast_helper.Exp.constant(Pconst_string(evm_name, None));
168162
Ast_helper.Exp.case(pattern, [%expr `String([%e expr])]);
169163
});
170164
Ast_helper.Exp.match([%expr value], match_arms);

0 commit comments

Comments
 (0)