@@ -84,6 +84,14 @@ exception Error_forward of Location.error
8484
8585(* Forward declaration, to be filled in by Typemod.type_module *)
8686
87+ let delayed_typechecking_errors = ref []
88+
89+ let add_delayed_error e =
90+ delayed_typechecking_errors := e :: ! delayed_typechecking_errors
91+
92+ let get_first_delayed_error () =
93+ List. nth_opt (! delayed_typechecking_errors |> List. rev) 0
94+
8795let type_module =
8896 ref
8997 (fun _env _md -> assert false
@@ -261,6 +269,18 @@ let option_none ty loc =
261269 let cnone = Env. lookup_constructor lid env in
262270 mkexp (Texp_construct (mknoloc lid, cnone, [] )) ty loc env
263271
272+ let tainted () =
273+ let lid = Longident. Lident " None" and env = Env. initial_safe_string in
274+ let cnone = Env. lookup_constructor lid env in
275+ {
276+ exp_desc = Texp_construct (mknoloc lid, cnone, [] );
277+ exp_type = newconstr Predef. path_tainted [] ;
278+ exp_loc = Location. none;
279+ exp_env = env;
280+ exp_extra = [] ;
281+ exp_attributes = [(Location. mknoloc " tainted" , PStr [] )];
282+ }
283+
264284let option_some texp =
265285 let lid = Longident. Lident " Some" in
266286 let csome = Env. lookup_constructor lid Env. initial_safe_string in
@@ -2246,6 +2266,11 @@ and type_expect ?type_clash_context ?in_function ?recarg env sexp ty_expected =
22462266 in
22472267 Cmt_format. set_saved_types
22482268 (Cmt_format. Partial_expression exp :: previous_saved_types);
2269+
2270+ (match get_first_delayed_error () with
2271+ | None -> ()
2272+ | Some e -> raise e);
2273+
22492274 exp
22502275
22512276and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected ) env sexp
@@ -3531,7 +3556,15 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
35313556 ( List. map
35323557 (function
35333558 | l , None -> (l, None )
3534- | l , Some f -> (l, Some (f () )))
3559+ | l , Some f ->
3560+ ( l,
3561+ Some
3562+ (if ! Clflags. editor_mode then (
3563+ try f ()
3564+ with e ->
3565+ add_delayed_error e;
3566+ tainted () )
3567+ else f () ) ))
35353568 (List. rev args),
35363569 instance env (result_type omitted ty_fun) )
35373570 in
0 commit comments