@@ -98,6 +98,8 @@ let extract_concrete_typedecl: (Env.t ->
98
98
Types. type_expr ->
99
99
Path. t * Path. t * Types. type_declaration) ref = ref (Obj. magic () )
100
100
101
+ let expand_head: (Env. t -> Types. type_expr -> Types. type_expr) ref = ref (Obj. magic () )
102
+
101
103
let process_tag_type (attrs : Parsetree.attributes ) =
102
104
let st : tag_type option ref = ref None in
103
105
Ext_list. iter attrs (fun ({txt; loc} , payload ) ->
@@ -158,34 +160,33 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
158
160
| _ -> None )
159
161
| _ -> None
160
162
161
- let get_block_type ~env (cstr : Types.constructor_declaration ) :
162
- block_type option =
163
- match (process_untagged cstr.cd_attributes, cstr.cd_args) with
164
- | false , _ -> None
165
- | true , Cstr_tuple [{desc = Tconstr (path, _, _)}]
166
- when Path. same path Predef. path_string ->
163
+ let get_block_type_from_typ ~env (t : Types.type_expr ) : block_type option =
164
+ let t = ! expand_head env t in
165
+ match t with
166
+ | {desc = Tconstr (path , _ , _ )} when Path. same path Predef. path_string ->
167
167
Some StringType
168
- | true , Cstr_tuple [{desc = Tconstr (path, _, _)}]
169
- when Path. same path Predef. path_int ->
168
+ | {desc = Tconstr (path , _ , _ )} when Path. same path Predef. path_int ->
170
169
Some IntType
171
- | true , Cstr_tuple [{desc = Tconstr (path, _, _)}]
172
- when Path. same path Predef. path_float ->
170
+ | {desc = Tconstr (path , _ , _ )} when Path. same path Predef. path_float ->
173
171
Some FloatType
174
- | true , Cstr_tuple [({desc = Tconstr _} as t)]
175
- when Ast_uncurried_utils. typeIsUncurriedFun t ->
172
+ | ({desc = Tconstr _ } as t ) when Ast_uncurried_utils. typeIsUncurriedFun t ->
176
173
Some FunctionType
177
- | true , Cstr_tuple [{desc = Tarrow _}] -> Some FunctionType
178
- | true , Cstr_tuple [{desc = Tconstr (path, _, _)}]
179
- when Path. same path Predef. path_string ->
174
+ | {desc = Tarrow _ } -> Some FunctionType
175
+ | {desc = Tconstr (path , _ , _ )} when Path. same path Predef. path_string ->
180
176
Some StringType
181
- | true , Cstr_tuple [({desc = Tconstr _} as t)] when type_is_builtin_object t
182
- ->
177
+ | ({desc = Tconstr _ } as t ) when type_is_builtin_object t ->
183
178
Some ObjectType
184
- | true , Cstr_tuple [({desc = Tconstr _} as t)] when type_to_instanceof_backed_obj t |> Option. is_some
185
- ->
179
+ | ({desc = Tconstr _ } as t ) when type_to_instanceof_backed_obj t |> Option. is_some ->
186
180
(match type_to_instanceof_backed_obj t with
187
181
| None -> None
188
182
| Some instanceType -> Some (InstanceType instanceType))
183
+ | _ -> None
184
+
185
+ let get_block_type ~env (cstr : Types.constructor_declaration ) :
186
+ block_type option =
187
+ match (process_untagged cstr.cd_attributes, cstr.cd_args) with
188
+ | false , _ -> None
189
+ | true , Cstr_tuple [{desc = Tconstr _} as t] when get_block_type_from_typ ~env t |> Option. is_some -> get_block_type_from_typ ~env t
189
190
| true , Cstr_tuple [ty] -> (
190
191
let default = Some UnknownType in
191
192
match ! extract_concrete_typedecl env ty with
0 commit comments