1
- let find_attribute_payload name (attributes : Parsetree.attribute list ) =
2
- attributes
3
- |> List. find_map (fun (attr : Parsetree.attribute ) ->
4
- match attr with
5
- | {txt} , payload when txt = name -> Some payload
6
- | _ -> None )
7
-
8
- let find_as_attribute_payload (attributes : Parsetree.attribute list ) =
9
- find_attribute_payload " as" attributes
10
-
11
1
(* TODO: Improve error messages? Say why we can't coerce. *)
12
2
13
3
let check_constructors (constructors : Types.constructor_declaration list ) check
14
4
=
15
5
List. for_all
16
6
(fun (c : Types.constructor_declaration ) ->
17
- check c.cd_args (find_as_attribute_payload c.cd_attributes))
7
+ check c.cd_args (Ast_untagged_variants. process_tag_type c.cd_attributes))
18
8
constructors
19
9
20
10
let can_coerce_to_string (constructors : Types.constructor_declaration list ) =
21
11
check_constructors constructors (fun args payload ->
22
12
match (args, payload) with
23
- | Cstr_tuple [] , None -> true
24
- | Cstr_tuple [] , Some payload
25
- when Ast_payload. is_single_string payload |> Option. is_some ->
26
- true
13
+ | Cstr_tuple [] , (None | Some (String _ )) -> true
27
14
| _ -> false )
28
15
29
16
let can_coerce_to_int (constructors : Types.constructor_declaration list ) =
30
17
check_constructors constructors (fun args payload ->
31
18
match (args, payload) with
32
- | Cstr_tuple [] , Some payload
33
- when Ast_payload. is_single_int payload |> Option. is_some ->
34
- true
19
+ | Cstr_tuple [] , Some (Int _ ) -> true
35
20
| _ -> false )
36
21
37
22
let can_coerce_to_float (constructors : Types.constructor_declaration list ) =
38
23
check_constructors constructors (fun args payload ->
39
24
match (args, payload) with
40
- | Cstr_tuple [] , Some payload
41
- when Ast_payload. is_single_float payload |> Option. is_some ->
42
- true
25
+ | Cstr_tuple [] , Some (Float _ ) -> true
43
26
| _ -> false )
44
27
45
28
let can_coerce_path (path : Path.t ) =
@@ -66,7 +49,8 @@ let is_variant_typedecl
66
49
let variant_representation_matches (c1_attrs : Parsetree.attributes )
67
50
(c2_attrs : Parsetree.attributes ) =
68
51
match
69
- (Ast_untagged_variants. process_tag_type c1_attrs, Ast_untagged_variants. process_tag_type c2_attrs)
52
+ ( Ast_untagged_variants. process_tag_type c1_attrs,
53
+ Ast_untagged_variants. process_tag_type c2_attrs )
70
54
with
71
55
| None , None -> true
72
56
| Some s1 , Some s2 when s1 = s2 -> true
@@ -76,7 +60,8 @@ let variant_configuration_can_be_coerced (a1 : Parsetree.attributes)
76
60
(a2 : Parsetree.attributes ) =
77
61
let unboxed =
78
62
match
79
- (Ast_untagged_variants. process_untagged a1, Ast_untagged_variants. process_untagged a2)
63
+ ( Ast_untagged_variants. process_untagged a1,
64
+ Ast_untagged_variants. process_untagged a2 )
80
65
with
81
66
| true , true | false , false -> true
82
67
| _ -> false
@@ -85,11 +70,11 @@ let variant_configuration_can_be_coerced (a1 : Parsetree.attributes)
85
70
else
86
71
let tag =
87
72
match
88
- (Ast_untagged_variants. process_tag_name a1,
73
+ ( Ast_untagged_variants. process_tag_name a1,
89
74
Ast_untagged_variants. process_tag_name a2 )
90
75
with
91
- | Some ( tag1 ) , Some ( tag2 ) when tag1 = tag2 -> true
76
+ | Some tag1 , Some tag2 when tag1 = tag2 -> true
92
77
| None , None -> true
93
78
| _ -> false
94
79
in
95
- if not tag then false else true
80
+ if not tag then false else true
0 commit comments