@@ -5916,8 +5916,7 @@ end = struct
59165916 let result = make_call env te tal tel typed_unpack_element ty in
59175917 (result, should_forget_fakes)
59185918 in
5919- let type_structure_impl pos e1 e2 =
5920- let should_forget_fakes = false in
5919+ let type_structure_impl ~fn pos e1 e2 =
59215920 match Aast_utils. arg_to_expr e2 with
59225921 | (_ , p , String cst ) ->
59235922 (* find the class constant implicitly defined by the typeconst *)
@@ -5952,19 +5951,18 @@ end = struct
59525951 Typing_error. (
59535952 primary
59545953 @@ Primary. Illegal_type_structure
5955- { pos; msg = " Could not resolve the type constant" })
5954+ { pos; msg = " Could not resolve the type constant" ; fn })
59565955 | _ -> ()
59575956 in
5958- ( result, should_forget_fakes)
5957+ result
59595958 | _ ->
59605959 Typing_error_utils. add_typing_error
59615960 ~env
59625961 Typing_error. (
59635962 primary
59645963 @@ Primary. Illegal_type_structure
5965- { pos; msg = " Second argument is not a string" });
5966- let result = expr_error env pos e in
5967- (result, should_forget_fakes)
5964+ { pos; msg = " Second argument is not a string" ; fn });
5965+ expr_error env pos e
59685966 in
59695967 match fun_expr with
59705968 (* Special top-level function *)
@@ -6129,8 +6127,52 @@ end = struct
61296127 when String. equal type_structure SN.StdlibFunctions. type_structure
61306128 && Int. equal (List. length el) 2
61316129 && Option. is_none unpacked_element ->
6130+ let should_forget_fakes = false in
6131+ (match el with
6132+ | [e1; e2] ->
6133+ let result = type_structure_impl ~fn: type_structure pos e1 e2 in
6134+ (result, should_forget_fakes)
6135+ | _ -> assert false )
6136+ | type_structure_classname
6137+ when String. equal
6138+ type_structure_classname
6139+ SN.StdlibFunctions. type_structure_classname
6140+ && Int. equal (List. length el) 2
6141+ && Option. is_none unpacked_element ->
6142+ let should_forget_fakes = false in
61326143 (match el with
6133- | [e1; e2] -> type_structure_impl pos e1 e2
6144+ | [e1; e2] ->
6145+ let (env, te, const_ty) =
6146+ type_structure_impl ~fn: type_structure_classname pos e1 e2
6147+ in
6148+ let (env, const_ty) = Env. expand_type env const_ty in
6149+ let (env, const_ty) =
6150+ Typing_dynamic_utils. strip_dynamic env const_ty
6151+ in
6152+ let result =
6153+ match get_node const_ty with
6154+ | Tnewtype (name, [ty_arg], _)
6155+ when String. equal name SN.FB. cTypeStructure ->
6156+ if Typing_structure. is_enum_or_classish env ty_arg then
6157+ let ty = MakeType. classname (get_reason const_ty) [ty_arg] in
6158+ (env, te, ty)
6159+ else begin
6160+ Typing_error_utils. add_typing_error
6161+ ~env
6162+ Typing_error. (
6163+ primary
6164+ @@ Primary. Illegal_type_structure
6165+ {
6166+ pos;
6167+ msg =
6168+ " The type constant does not resolve to a classish type" ;
6169+ fn = type_structure_classname;
6170+ });
6171+ expr_error env pos e
6172+ end
6173+ | _ -> expr_error env pos e
6174+ in
6175+ (result, should_forget_fakes)
61346176 | _ -> assert false )
61356177 | _ -> dispatch_id env id
61366178 end
0 commit comments