@@ -119,7 +119,29 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
119119 else (* ([`a|`b] [@bs.string]) *)
120120 ptyp, spec_of_ptyp nolabel ptyp
121121
122- let refine_obj_arg_type = refine_arg_type
122+ let refine_obj_arg_type ~(nolabel :bool ) (ptyp : Ast_core_type.t )
123+ : Ast_core_type.t * External_arg_spec.attr =
124+ if ptyp.ptyp_desc = Ptyp_any then
125+ let ptyp_attrs = ptyp.ptyp_attributes in
126+ let result = Ast_attributes. iter_process_bs_string_or_int_as ptyp_attrs in
127+ (* when ppx start dropping attributes
128+ we should warn, there is a trade off whether
129+ we should warn dropped non bs attribute or not
130+ *)
131+ Bs_ast_invariant. warn_discarded_unused_attributes ptyp_attrs;
132+ match result with
133+ | None ->
134+ Bs_syntaxerr. err ptyp.ptyp_loc Invalid_underscore_type_in_external
135+ | Some (Int i ) -> (* (_[@bs.as ])*)
136+ (* This type is used in bs.obj only to construct obj type*)
137+ Ast_literal. type_int ~loc: ptyp.ptyp_loc () , Arg_cst (External_arg_spec. cst_int i)
138+ | Some (Str i )->
139+ Ast_literal. type_string ~loc: ptyp.ptyp_loc () , Arg_cst (External_arg_spec. cst_string i)
140+ | Some (Json_str _ ) ->
141+ Location. raise_errorf ~loc: ptyp.ptyp_loc " json payload is not supported in bs.obj since its type can not be inferred"
142+ else (* ([`a|`b] [@bs.string]) *)
143+ ptyp, spec_of_ptyp nolabel ptyp
144+
123145(* * Given the type of argument, process its [bs.] attribute and new type,
124146 The new type is currently used to reconstruct the external type
125147 and result type in [@@bs.obj]
0 commit comments