@@ -92,7 +92,7 @@ let () =
92
92
None
93
93
)
94
94
95
- let get_untagged (cstr : Types.constructor_declaration ) : block_type option =
95
+ let get_untagged ~ env (cstr : Types.constructor_declaration ) : block_type option =
96
96
match process_untagged cstr.cd_attributes, cstr.cd_args with
97
97
| false , _ -> None
98
98
| true , Cstr_tuple [{desc = Tconstr (path, _, _)}] when Path. same path Predef. path_string ->
@@ -105,17 +105,21 @@ let get_untagged (cstr: Types.constructor_declaration) : block_type option =
105
105
Some Array
106
106
| true , Cstr_tuple [{desc = Tconstr (path, _, _)}] when Path. same path Predef. path_string ->
107
107
Some StringType
108
- | true , Cstr_tuple [{desc = Tconstr (path, _, _)}] ->
109
- (match Path. name path with
110
- | " Js.Dict.t"
111
- | "Js_dict.t" -> Some Object
112
- | _ -> Some Unknown )
113
- | true , Cstr_tuple (_ :: _ :: _ ) ->
108
+ | true , Cstr_tuple [{desc = Tconstr (path, _, _)}] when
109
+ let name = Path. name path in
110
+ name = " Js.Dict.t" || name = " Js_dict.t" ->
111
+ Some Object
112
+ | true , Cstr_tuple [ty] ->
113
+ let default = Some Unknown in
114
+ (match Ctype. extract_concrete_typedecl env ty with
115
+ | (_ , _ , {type_kind = Type_record (_ , Record_unboxed _ )} ) -> default
116
+ | (_ , _ , {type_kind = Type_record (_ , _ )} ) -> Some Object
117
+ | _ -> default
118
+ | exception _ -> default
119
+ )
120
+ | true , Cstr_tuple (_ :: _ :: _ ) ->
114
121
(* C(_, _) with at least 2 args is an object *)
115
122
Some Object
116
- | true , Cstr_tuple [_] ->
117
- (* Every other single payload is unknown *)
118
- Some Unknown
119
123
| true , Cstr_record _ ->
120
124
(* inline record is an object *)
121
125
Some Object
@@ -209,13 +213,13 @@ let checkInvariant ~isUntaggedDef ~(consts : (Location.t * literal) list) ~(bloc
209
213
invariant loc
210
214
| None -> () )
211
215
212
- let names_from_type_variant ?(isUntaggedDef =false ) (cstrs : Types.constructor_declaration list ) =
216
+ let names_from_type_variant ?(isUntaggedDef =false ) ~ env (cstrs : Types.constructor_declaration list ) =
213
217
let get_cstr_name (cstr : Types.constructor_declaration ) =
214
218
(cstr.cd_loc,
215
219
{ name = Ident. name cstr.cd_id;
216
220
literal_type = process_literal_type cstr.cd_attributes }) in
217
221
let get_block cstr : block =
218
- {literal = snd (get_cstr_name cstr); tag_name = get_tag_name cstr; block_type = get_untagged cstr} in
222
+ {literal = snd (get_cstr_name cstr); tag_name = get_tag_name cstr; block_type = get_untagged ~env cstr} in
219
223
let consts, blocks =
220
224
Ext_list. fold_left cstrs ([] , [] ) (fun (consts , blocks ) cstr ->
221
225
if is_nullary_variant cstr.cd_args then
@@ -229,6 +233,6 @@ let names_from_type_variant ?(isUntaggedDef=false) (cstrs : Types.constructor_de
229
233
let blocks = Ext_array. reverse_of_list blocks in
230
234
Some { consts; blocks }
231
235
232
- let check_well_formed ~isUntaggedDef (cstrs : Types.constructor_declaration list ) =
233
- ignore (names_from_type_variant ~is UntaggedDef cstrs)
236
+ let check_well_formed ~env ~ isUntaggedDef (cstrs : Types.constructor_declaration list ) =
237
+ ignore (names_from_type_variant ~env ~ is UntaggedDef cstrs)
234
238
0 commit comments