@@ -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
@@ -264,6 +272,18 @@ let option_none ty loc =
264272 let cnone = Env. lookup_constructor lid env in
265273 mkexp (Texp_construct (mknoloc lid, cnone, [] )) ty loc env
266274
275+ let tainted () =
276+ let lid = Longident. Lident " None" and env = Env. initial_safe_string in
277+ let cnone = Env. lookup_constructor lid env in
278+ {
279+ exp_desc = Texp_construct (mknoloc lid, cnone, [] );
280+ exp_type = newconstr Predef. path_tainted [] ;
281+ exp_loc = Location. none;
282+ exp_env = env;
283+ exp_extra = [] ;
284+ exp_attributes = [(Location. mknoloc " tainted" , PStr [] )];
285+ }
286+
267287let option_some texp =
268288 let lid = Longident. Lident " Some" in
269289 let csome = Env. lookup_constructor lid Env. initial_safe_string in
@@ -2249,6 +2269,11 @@ and type_expect ?type_clash_context ?in_function ?recarg env sexp ty_expected =
22492269 in
22502270 Cmt_format. set_saved_types
22512271 (Cmt_format. Partial_expression exp :: previous_saved_types);
2272+
2273+ (match get_first_delayed_error () with
2274+ | None -> ()
2275+ | Some e -> raise e);
2276+
22522277 exp
22532278
22542279and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected ) env sexp
@@ -3537,7 +3562,15 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
35373562 ( List. map
35383563 (function
35393564 | l , None -> (l, None )
3540- | l , Some f -> (l, Some (f () )))
3565+ | l , Some f ->
3566+ ( l,
3567+ Some
3568+ (if ! Clflags. editor_mode then (
3569+ try f ()
3570+ with e ->
3571+ add_delayed_error e;
3572+ tainted () )
3573+ else f () ) ))
35413574 (List. rev args),
35423575 instance env (result_type omitted ty_fun) )
35433576 in
0 commit comments