@@ -275,7 +275,7 @@ let option_none ty loc =
275
275
let cnone = Env. lookup_constructor lid env in
276
276
mkexp (Texp_construct (mknoloc lid, cnone, [] )) ty loc env
277
277
278
- let tainted () =
278
+ let tainted_expr () =
279
279
let lid = Longident. Lident " None" and env = Env. initial_safe_string in
280
280
let cnone = Env. lookup_constructor lid env in
281
281
{
@@ -287,6 +287,19 @@ let tainted () =
287
287
exp_attributes = [(Location. mknoloc " tainted" , PStr [] )];
288
288
}
289
289
290
+ let tainted_pat expected_type =
291
+ let env = Env. initial_safe_string in
292
+ {
293
+ pat_desc = Tpat_var (Ident. create " tainted$" , Location. mknoloc " tainted$" );
294
+ pat_type = expected_type;
295
+ pat_loc = Location. none;
296
+ pat_env = env;
297
+ pat_extra = [] ;
298
+ pat_attributes = [(Location. mknoloc " tainted" , PStr [] )];
299
+ }
300
+
301
+ let _ = ignore tainted_pat
302
+
290
303
let option_some texp =
291
304
let lid = Longident. Lident " Some" in
292
305
let csome = Env. lookup_constructor lid Env. initial_safe_string in
@@ -1526,21 +1539,27 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env sp
1526
1539
if vars = [] then end_def () ;
1527
1540
(try unify_pat_types loc ! env ty_res record_ty
1528
1541
with Unify trace ->
1529
- raise
1542
+ raise_or_continue
1530
1543
(Error (label_lid.loc, ! env, Label_mismatch (label_lid.txt, trace))));
1531
- type_pat sarg ty_arg (fun arg ->
1532
- if vars <> [] then (
1533
- end_def () ;
1534
- generalize ty_arg;
1535
- List. iter generalize vars;
1536
- let instantiated tv =
1537
- let tv = expand_head ! env tv in
1538
- (not (is_Tvar tv)) || tv.level <> generic_level
1539
- in
1540
- if List. exists instantiated vars then
1541
- raise
1542
- (Error (label_lid.loc, ! env, Polymorphic_label label_lid.txt)));
1543
- k (label_lid, label, arg, opt))
1544
+ try
1545
+ type_pat sarg ty_arg (fun arg ->
1546
+ if vars <> [] then (
1547
+ end_def () ;
1548
+ generalize ty_arg;
1549
+ List. iter generalize vars;
1550
+ let instantiated tv =
1551
+ let tv = expand_head ! env tv in
1552
+ (not (is_Tvar tv)) || tv.level <> generic_level
1553
+ in
1554
+ if List. exists instantiated vars then
1555
+ raise_or_continue
1556
+ (Error (label_lid.loc, ! env, Polymorphic_label label_lid.txt)));
1557
+ k (label_lid, label, arg, opt))
1558
+ with err ->
1559
+ if ! Clflags. editor_mode then (
1560
+ add_delayed_error err;
1561
+ k (label_lid, label, tainted_pat ty_arg, opt))
1562
+ else raise err
1544
1563
in
1545
1564
let k' k lbl_pat_list =
1546
1565
check_recordpat_labels ~get_jsx_component_error_info loc lbl_pat_list
@@ -3572,7 +3591,7 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
3572
3591
( l,
3573
3592
Some
3574
3593
(if ! Clflags. editor_mode then
3575
- try f () with _ -> tainted ()
3594
+ try f () with _ -> tainted_expr ()
3576
3595
else f () ) ))
3577
3596
(List. rev args),
3578
3597
instance env (result_type omitted ty_fun) )
0 commit comments