@@ -92,7 +92,7 @@ let () =
9292 None
9393 )
9494
95- let get_untagged (cstr : Types.constructor_declaration ) : block_type option =
95+ let get_untagged ~ env (cstr : Types.constructor_declaration ) : block_type option =
9696 match process_untagged cstr.cd_attributes, cstr.cd_args with
9797 | false , _ -> None
9898 | 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 =
105105 Some Array
106106 | true , Cstr_tuple [{desc = Tconstr (path, _, _)}] when Path. same path Predef. path_string ->
107107 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 (_ :: _ :: _ ) ->
114121 (* C(_, _) with at least 2 args is an object *)
115122 Some Object
116- | true , Cstr_tuple [_] ->
117- (* Every other single payload is unknown *)
118- Some Unknown
119123 | true , Cstr_record _ ->
120124 (* inline record is an object *)
121125 Some Object
@@ -209,13 +213,13 @@ let checkInvariant ~isUntaggedDef ~(consts : (Location.t * literal) list) ~(bloc
209213 invariant loc
210214 | None -> () )
211215
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 ) =
213217 let get_cstr_name (cstr : Types.constructor_declaration ) =
214218 (cstr.cd_loc,
215219 { name = Ident. name cstr.cd_id;
216220 literal_type = process_literal_type cstr.cd_attributes }) in
217221 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
219223 let consts, blocks =
220224 Ext_list. fold_left cstrs ([] , [] ) (fun (consts , blocks ) cstr ->
221225 if is_nullary_variant cstr.cd_args then
@@ -229,6 +233,6 @@ let names_from_type_variant ?(isUntaggedDef=false) (cstrs : Types.constructor_de
229233 let blocks = Ext_array. reverse_of_list blocks in
230234 Some { consts; blocks }
231235
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)
234238
0 commit comments