@@ -49,7 +49,9 @@ module T = struct
4949 | Ptyp_var _ -> ()
5050 | Ptyp_arrow (_lab , t1 , t2 ) ->
5151 sub.typ sub t1; sub.typ sub t2
52- | Ptyp_tuple tyl -> List. iter (sub.typ sub) tyl
52+ (* Unpack the label tuple for 5.4.1 *)
53+ | Ptyp_tuple tyl ->
54+ List. iter (fun (_ , t ) -> sub.typ sub t) tyl
5355 | Ptyp_constr (lid , tl ) ->
5456 iter_loc sub lid; List. iter (sub.typ sub) tl
5557 | Ptyp_object (ol , _o ) ->
@@ -60,10 +62,13 @@ module T = struct
6062 | Ptyp_variant (rl , _b , _ll ) ->
6163 List. iter (row_field sub) rl
6264 | Ptyp_poly (_ , t ) -> sub.typ sub t
63- | Ptyp_package (lid , l ) ->
65+ (* Unpack the new package_type record for 5.4.1 *)
66+ | Ptyp_package { ppt_path = lid ; ppt_cstrs = l ; _ } ->
6467 iter_loc sub lid;
6568 List. iter (iter_tuple (iter_loc sub) (sub.typ sub)) l
6669 | Ptyp_extension x -> sub.extension sub x
70+ | Ptyp_open (lid , t ) ->
71+ iter_loc sub lid; sub.typ sub t
6772
6873 let iter_type_declaration sub
6974 {ptype_name; ptype_params; ptype_cstrs;
@@ -113,7 +118,7 @@ module T = struct
113118 sub.attributes sub ptyexn_attributes
114119
115120 let iter_extension_constructor_kind sub = function
116- Pext_decl (ctl , cto ) ->
121+ Pext_decl (_ , ctl , cto ) ->
117122 iter_constructor_arguments sub ctl; iter_opt (sub.typ sub) cto
118123 | Pext_rebind li ->
119124 iter_loc sub li
@@ -244,6 +249,7 @@ module M = struct
244249 sub.module_expr sub body
245250 | Pmod_apply (m1 , m2 ) ->
246251 sub.module_expr sub m1; sub.module_expr sub m2
252+ | Pmod_apply_unit m -> sub.module_expr sub m
247253 | Pmod_constraint (m , mty ) ->
248254 sub.module_expr sub m; sub.module_type sub mty
249255 | Pmod_unpack e -> sub.expr sub e
@@ -284,17 +290,35 @@ module E = struct
284290 | Pexp_let (_r , vbs , e ) ->
285291 List. iter (sub.value_binding sub) vbs;
286292 sub.expr sub e
287- | Pexp_fun (_lab , def , p , e ) ->
288- iter_opt (sub.expr sub) def;
289- sub.pat sub p;
290- sub.expr sub e
291- | Pexp_function pel -> sub.cases sub pel
293+ (* Handle consolidated Pexp_function in >=5.2 *)
294+ | Pexp_function (params , constraint_opt , body ) ->
295+ List. iter
296+ (fun param ->
297+ match param.pparam_desc with
298+ | Pparam_val (_lab , def , p ) ->
299+ iter_opt (sub.expr sub) def;
300+ sub.pat sub p
301+ | Pparam_newtype _ -> ()
302+ ) params;
303+
304+ begin match constraint_opt with
305+ | Some (Pconstraint ty ) -> sub.typ sub ty
306+ | Some (Pcoerce (ty1_opt , ty2 )) ->
307+ iter_opt (sub.typ sub) ty1_opt;
308+ sub.typ sub ty2
309+ | None -> ()
310+ end ;
311+
312+ begin match body with
313+ | Pfunction_body e -> sub.expr sub e
314+ | Pfunction_cases (cases , _loc , _attrs ) -> sub.cases sub cases
315+ end
292316 | Pexp_apply (e , l ) ->
293317 sub.expr sub e; List. iter (iter_snd (sub.expr sub)) l
294318 | Pexp_match (e , pel ) ->
295319 sub.expr sub e; sub.cases sub pel
296320 | Pexp_try (e , pel ) -> sub.expr sub e; sub.cases sub pel
297- | Pexp_tuple el -> List. iter (sub.expr sub) el
321+ | Pexp_tuple el -> List. iter (fun ( _ , pat ) -> ( sub.expr sub pat) ) el
298322 | Pexp_construct (lid , arg ) ->
299323 iter_loc sub lid; iter_opt (sub.expr sub) arg
300324 | Pexp_variant (_lab , eo ) ->
@@ -341,7 +365,15 @@ module E = struct
341365 sub.expr sub e; iter_opt (sub.typ sub) t
342366 | Pexp_object cls -> sub.class_structure sub cls
343367 | Pexp_newtype (_s , e ) -> sub.expr sub e
344- | Pexp_pack me -> sub.module_expr sub me
368+ | Pexp_pack (me , pt_opt ) ->
369+ sub.module_expr sub me;
370+ (* Unpack and traverse the optional package_type record *)
371+ begin match pt_opt with
372+ | Some { ppt_path = lid ; ppt_cstrs = l ; _ } ->
373+ iter_loc sub lid;
374+ List. iter (iter_tuple (iter_loc sub) (sub.typ sub)) l
375+ | None -> ()
376+ end
345377 | Pexp_open (o , e ) ->
346378 sub.open_declaration sub o; sub.expr sub e
347379 | Pexp_letop {let_; ands; body} ->
@@ -371,7 +403,7 @@ module P = struct
371403 | Ppat_alias (p , s ) -> sub.pat sub p; iter_loc sub s
372404 | Ppat_constant _ -> ()
373405 | Ppat_interval _ -> ()
374- | Ppat_tuple pl -> List. iter (sub.pat sub) pl
406+ | Ppat_tuple ( pl , _ ) -> List. iter (fun ( _ , pat ) -> sub.pat sub pat ) pl
375407 | Ppat_construct (l , p ) ->
376408 iter_loc sub l; iter_opt (sub.pat sub) (Option. map snd p)
377409 | Ppat_variant (_l , p ) -> iter_opt (sub.pat sub) p
@@ -388,6 +420,7 @@ module P = struct
388420 | Ppat_extension x -> sub.extension sub x
389421 | Ppat_open (lid , p ) ->
390422 iter_loc sub lid; sub.pat sub p
423+ | Ppat_effect (p1 , p2 ) -> sub.pat sub p1; sub.pat sub p2
391424
392425end
393426
0 commit comments