@@ -2527,18 +2527,30 @@ let unexpanded_diff ~got ~expected =
2527
2527
2528
2528
(* *** Unification ****)
2529
2529
2530
- (* Return whether [t0] occurs in [ty]. Objects are also traversed. *)
2530
+ let rec deep_occur_rec t0 ty =
2531
+ if get_level ty > = get_level t0 && try_mark_node ty then begin
2532
+ if eq_type ty t0 then raise Occur ;
2533
+ iter_type_expr (deep_occur_rec t0) ty
2534
+ end
2535
+
2536
+ (* Return whether [t0] occurs in any type in [tyl]. Objects are also traversed. *)
2537
+ let deep_occur_list t0 tyl =
2538
+ try
2539
+ List. iter (deep_occur_rec t0) tyl;
2540
+ List. iter unmark_type tyl;
2541
+ false
2542
+ with Occur ->
2543
+ List. iter unmark_type tyl;
2544
+ true
2545
+
2531
2546
let deep_occur t0 ty =
2532
- let rec occur_rec ty =
2533
- if get_level ty > = get_level t0 && try_mark_node ty then begin
2534
- if eq_type ty t0 then raise Occur ;
2535
- iter_type_expr occur_rec ty
2536
- end
2537
- in
2538
2547
try
2539
- occur_rec ty; unmark_type ty; false
2548
+ deep_occur_rec t0 ty;
2549
+ unmark_type ty;
2550
+ false
2540
2551
with Occur ->
2541
- unmark_type ty; true
2552
+ unmark_type ty;
2553
+ true
2542
2554
2543
2555
let gadt_equations_level = ref None
2544
2556
@@ -5286,7 +5298,7 @@ let rec build_subtype env (visited : transient_expr list)
5286
5298
(* Fix PR#4505: do not set ty to Tvar when it appears in tl1,
5287
5299
as this occurrence might break the occur check.
5288
5300
XXX not clear whether this correct anyway... *)
5289
- if List. exists (deep_occur ty) tl1 then raise Not_found ;
5301
+ if deep_occur_list ty tl1 then raise Not_found ;
5290
5302
set_type_desc ty
5291
5303
(Tvar { name = None ;
5292
5304
layout = Layout. value
@@ -5844,7 +5856,7 @@ let rec normalize_type_rec visited ty =
5844
5856
begin match ! nm with
5845
5857
| None -> ()
5846
5858
| Some (n , v :: l ) ->
5847
- if deep_occur ty (newgenty ( Ttuple l)) then
5859
+ if deep_occur_list ty l then
5848
5860
(* The abbreviation may be hiding something, so remove it *)
5849
5861
set_name nm None
5850
5862
else
0 commit comments