@@ -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
@@ -322,15 +328,18 @@ let check_optional_attr env ld optional loc =
322
328
(* unification inside type_pat*)
323
329
let unify_pat_types loc env ty ty' =
324
330
try unify env ty ty' with
325
- | Unify trace -> raise (Error (loc, env, Pattern_type_clash trace))
331
+ | Unify trace ->
332
+ raise_or_continue (Error (loc, env, Pattern_type_clash trace))
326
333
| Tags (l1 , l2 ) ->
327
- raise (Typetexp. Error (loc, env, Typetexp. Variant_tags (l1, l2)))
334
+ raise_or_continue
335
+ (Typetexp. Error (loc, env, Typetexp. Variant_tags (l1, l2)))
328
336
329
337
(* unification inside type_exp and type_expect *)
330
338
let unify_exp_types ?type_clash_context loc env ty expected_ty =
331
339
try unify env ty expected_ty with
332
340
| Unify trace ->
333
- raise (Error (loc, env, Expr_type_clash (trace, type_clash_context)))
341
+ raise_or_continue
342
+ (Error (loc, env, Expr_type_clash (trace, type_clash_context)))
334
343
| Tags (l1 , l2 ) ->
335
344
raise (Typetexp. Error (loc, env, Typetexp. Variant_tags (l1, l2)))
336
345
@@ -348,11 +357,13 @@ let unify_pat_types_gadt loc env ty ty' =
348
357
| Some x -> x
349
358
in
350
359
try unify_gadt ~newtype_level env ty ty' with
351
- | Unify trace -> raise (Error (loc, ! env, Pattern_type_clash trace))
360
+ | Unify trace ->
361
+ raise_or_continue (Error (loc, ! env, Pattern_type_clash trace))
352
362
| Tags (l1 , l2 ) ->
353
- raise (Typetexp. Error (loc, ! env, Typetexp. Variant_tags (l1, l2)))
363
+ raise_or_continue
364
+ (Typetexp. Error (loc, ! env, Typetexp. Variant_tags (l1, l2)))
354
365
| Unification_recursive_abbrev trace ->
355
- raise (Error (loc, ! env, Recursive_local_constraint trace))
366
+ raise_or_continue (Error (loc, ! env, Recursive_local_constraint trace))
356
367
357
368
(* Creating new conjunctive types is not allowed when typing patterns *)
358
369
@@ -460,7 +471,8 @@ let enter_orpat_variables loc env p1_vs p2_vs =
460
471
else (
461
472
(try unify env t1 t2
462
473
with Unify trace ->
463
- raise (Error (loc, env, Or_pattern_type_clash (x1, trace))));
474
+ raise_or_continue
475
+ (Error (loc, env, Or_pattern_type_clash (x1, trace))));
464
476
(x2, x1) :: unify_vars rem1 rem2)
465
477
| [] , [] -> []
466
478
| (x , _ , _ , _ , _ ) :: _ , [] -> raise (Error (loc, env, Orpat_vars (x, [] )))
@@ -1934,7 +1946,8 @@ let rec type_approx env sexp =
1934
1946
let ty1 = approx_type env sty in
1935
1947
(try unify env ty ty1
1936
1948
with Unify trace ->
1937
- raise (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1949
+ raise_or_continue
1950
+ (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1938
1951
ty1
1939
1952
| Pexp_coerce (e , () , sty2 ) ->
1940
1953
let approx_ty_opt = function
@@ -1946,7 +1959,8 @@ let rec type_approx env sexp =
1946
1959
and ty2 = approx_type env sty2 in
1947
1960
(try unify env ty ty1
1948
1961
with Unify trace ->
1949
- raise (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1962
+ raise_or_continue
1963
+ (Error (sexp.pexp_loc, env, Expr_type_clash (trace, None ))));
1950
1964
ty2
1951
1965
| _ -> newvar ()
1952
1966
@@ -2269,11 +2283,6 @@ and type_expect ?type_clash_context ?in_function ?recarg env sexp ty_expected =
2269
2283
in
2270
2284
Cmt_format. set_saved_types
2271
2285
(Cmt_format. Partial_expression exp :: previous_saved_types);
2272
-
2273
- (match get_first_delayed_error () with
2274
- | None -> ()
2275
- | Some e -> raise e);
2276
-
2277
2286
exp
2278
2287
2279
2288
and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected ) env sexp
@@ -2953,7 +2962,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
2953
2962
let gen = generalizable tv.level arg.exp_type in
2954
2963
(try unify_var env tv arg.exp_type
2955
2964
with Unify trace ->
2956
- raise
2965
+ raise_or_continue
2957
2966
(Error
2958
2967
(arg.exp_loc, env, Expr_type_clash (trace, type_clash_context))));
2959
2968
gen)
@@ -3351,8 +3360,11 @@ and type_label_exp ?type_clash_context create env loc ty_expected
3351
3360
(* Generalize information merged from ty_expected *)
3352
3361
generalize_structure ty_arg);
3353
3362
if label.lbl_private = Private then
3354
- if create then raise (Error (loc, env, Private_type ty_expected))
3355
- else raise (Error (lid.loc, env, Private_label (lid.txt, ty_expected)));
3363
+ if create then
3364
+ raise_or_continue (Error (loc, env, Private_type ty_expected))
3365
+ else
3366
+ raise_or_continue
3367
+ (Error (lid.loc, env, Private_label (lid.txt, ty_expected)));
3356
3368
let arg =
3357
3369
let snap = if vars = [] then None else Some (Btype. snapshot () ) in
3358
3370
let arg =
@@ -3565,11 +3577,8 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
3565
3577
| l , Some f ->
3566
3578
( l,
3567
3579
Some
3568
- (if ! Clflags. editor_mode then (
3569
- try f ()
3570
- with e ->
3571
- add_delayed_error e;
3572
- tainted () )
3580
+ (if ! Clflags. editor_mode then
3581
+ try f () with _ -> tainted ()
3573
3582
else f () ) ))
3574
3583
(List. rev args),
3575
3584
instance env (result_type omitted ty_fun) )
0 commit comments