@@ -80,6 +80,7 @@ type error =
80
80
| Type_params_not_supported of Longident .t
81
81
| Field_access_on_dict_type
82
82
exception Error of Location .t * Env .t * error
83
+ exception Errors of exn list
83
84
exception Error_forward of Location .error
84
85
85
86
(* Forward declaration, to be filled in by Typemod.type_module *)
@@ -89,8 +90,13 @@ let delayed_typechecking_errors = ref []
89
90
let add_delayed_error e =
90
91
delayed_typechecking_errors := e :: ! delayed_typechecking_errors
91
92
92
- let get_first_delayed_error () =
93
- List. nth_opt (! delayed_typechecking_errors |> List. rev) 0
93
+ let raise_delayed_error_if_exists () =
94
+ (* Might have duplicate errors, so remove those. *)
95
+ let errors = List. sort_uniq compare ! delayed_typechecking_errors in
96
+ if errors <> [] then raise (Errors errors)
97
+
98
+ let raise_or_continue exn =
99
+ if ! Clflags. editor_mode then add_delayed_error exn else raise exn
94
100
95
101
let type_module =
96
102
ref
@@ -319,15 +325,18 @@ let check_optional_attr env ld optional loc =
319
325
(* unification inside type_pat*)
320
326
let unify_pat_types loc env ty ty' =
321
327
try unify env ty ty' with
322
- | Unify trace -> raise (Error (loc, env, Pattern_type_clash trace))
328
+ | Unify trace ->
329
+ raise_or_continue (Error (loc, env, Pattern_type_clash trace))
323
330
| Tags (l1 , l2 ) ->
324
- raise (Typetexp. Error (loc, env, Typetexp. Variant_tags (l1, l2)))
331
+ raise_or_continue
332
+ (Typetexp. Error (loc, env, Typetexp. Variant_tags (l1, l2)))
325
333
326
334
(* unification inside type_exp and type_expect *)
327
335
let unify_exp_types ?type_clash_context loc env ty expected_ty =
328
336
try unify env ty expected_ty with
329
337
| Unify trace ->
330
- raise (Error (loc, env, Expr_type_clash (trace, type_clash_context)))
338
+ raise_or_continue
339
+ (Error (loc, env, Expr_type_clash (trace, type_clash_context)))
331
340
| Tags (l1 , l2 ) ->
332
341
raise (Typetexp. Error (loc, env, Typetexp. Variant_tags (l1, l2)))
333
342
@@ -345,11 +354,13 @@ let unify_pat_types_gadt loc env ty ty' =
345
354
| Some x -> x
346
355
in
347
356
try unify_gadt ~newtype_level env ty ty' with
348
- | Unify trace -> raise (Error (loc, ! env, Pattern_type_clash trace))
357
+ | Unify trace ->
358
+ raise_or_continue (Error (loc, ! env, Pattern_type_clash trace))
349
359
| Tags (l1 , l2 ) ->
350
- raise (Typetexp. Error (loc, ! env, Typetexp. Variant_tags (l1, l2)))
360
+ raise_or_continue
361
+ (Typetexp. Error (loc, ! env, Typetexp. Variant_tags (l1, l2)))
351
362
| Unification_recursive_abbrev trace ->
352
- raise (Error (loc, ! env, Recursive_local_constraint trace))
363
+ raise_or_continue (Error (loc, ! env, Recursive_local_constraint trace))
353
364
354
365
(* Creating new conjunctive types is not allowed when typing patterns *)
355
366
@@ -457,7 +468,8 @@ let enter_orpat_variables loc env p1_vs p2_vs =
457
468
else (
458
469
(try unify env t1 t2
459
470
with Unify trace ->
460
- raise (Error (loc, env, Or_pattern_type_clash (x1, trace))));
471
+ raise_or_continue
472
+ (Error (loc, env, Or_pattern_type_clash (x1, trace))));
461
473
(x2, x1) :: unify_vars rem1 rem2)
462
474
| [] , [] -> []
463
475
| (x , _ , _ , _ , _ ) :: _ , [] -> raise (Error (loc, env, Orpat_vars (x, [] )))
@@ -1931,7 +1943,8 @@ let rec type_approx env sexp =
1931
1943
let ty1 = approx_type env sty in
1932
1944
(try unify env ty ty1
1933
1945
with Unify trace ->
1934
- raise (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1946
+ raise_or_continue
1947
+ (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1935
1948
ty1
1936
1949
| Pexp_coerce (e , () , sty2 ) ->
1937
1950
let approx_ty_opt = function
@@ -1943,7 +1956,8 @@ let rec type_approx env sexp =
1943
1956
and ty2 = approx_type env sty2 in
1944
1957
(try unify env ty ty1
1945
1958
with Unify trace ->
1946
- raise (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1959
+ raise_or_continue
1960
+ (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1947
1961
ty2
1948
1962
| _ -> newvar ()
1949
1963
@@ -2266,11 +2280,6 @@ and type_expect ?type_clash_context ?in_function ?recarg env sexp ty_expected =
2266
2280
in
2267
2281
Cmt_format. set_saved_types
2268
2282
(Cmt_format. Partial_expression exp :: previous_saved_types);
2269
-
2270
- (match get_first_delayed_error () with
2271
- | None -> ()
2272
- | Some e -> raise e);
2273
-
2274
2283
exp
2275
2284
2276
2285
and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected ) env sexp
@@ -2950,7 +2959,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
2950
2959
let gen = generalizable tv.level arg.exp_type in
2951
2960
(try unify_var env tv arg.exp_type
2952
2961
with Unify trace ->
2953
- raise
2962
+ raise_or_continue
2954
2963
(Error
2955
2964
(arg.exp_loc, env, Expr_type_clash (trace, type_clash_context))));
2956
2965
gen)
@@ -3345,8 +3354,11 @@ and type_label_exp ?type_clash_context create env loc ty_expected
3345
3354
(* Generalize information merged from ty_expected *)
3346
3355
generalize_structure ty_arg);
3347
3356
if label.lbl_private = Private then
3348
- if create then raise (Error (loc, env, Private_type ty_expected))
3349
- else raise (Error (lid.loc, env, Private_label (lid.txt, ty_expected)));
3357
+ if create then
3358
+ raise_or_continue (Error (loc, env, Private_type ty_expected))
3359
+ else
3360
+ raise_or_continue
3361
+ (Error (lid.loc, env, Private_label (lid.txt, ty_expected)));
3350
3362
let arg =
3351
3363
let snap = if vars = [] then None else Some (Btype. snapshot () ) in
3352
3364
let arg =
@@ -3559,11 +3571,8 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
3559
3571
| l , Some f ->
3560
3572
( l,
3561
3573
Some
3562
- (if ! Clflags. editor_mode then (
3563
- try f ()
3564
- with e ->
3565
- add_delayed_error e;
3566
- tainted () )
3574
+ (if ! Clflags. editor_mode then
3575
+ try f () with _ -> tainted ()
3567
3576
else f () ) ))
3568
3577
(List. rev args),
3569
3578
instance env (result_type omitted ty_fun) )
0 commit comments