Skip to content

Commit eb7c703

Browse files
committed
handle ppat_record labels as tainted
1 parent bac24c7 commit eb7c703

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

analysis/src/ProcessExtra.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ let pat ~(file : File.t) ~env ~extra (iter : Tast_iterator.iterator)
373373
(* Log.log("Entering pattern " ++ Utils.showLocation(pat_loc)); *)
374374
(match pattern.pat_desc with
375375
| Tpat_record (items, _) ->
376-
addForRecord ~env ~extra ~recordType:pattern.pat_type items
376+
addForRecord ~env ~extra ~recordType:pattern.pat_type items;
377+
addLocItem extra pattern.pat_loc (OtherPattern pattern.pat_type)
377378
| Tpat_construct (lident, constructor, _) ->
378379
addForConstructor ~env ~extra pattern.pat_type lident constructor
379380
| Tpat_alias (_inner, ident, name) ->

compiler/ml/typecore.ml

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ let option_none ty loc =
275275
let cnone = Env.lookup_constructor lid env in
276276
mkexp (Texp_construct (mknoloc lid, cnone, [])) ty loc env
277277

278-
let tainted () =
278+
let tainted_expr () =
279279
let lid = Longident.Lident "None" and env = Env.initial_safe_string in
280280
let cnone = Env.lookup_constructor lid env in
281281
{
@@ -287,6 +287,19 @@ let tainted () =
287287
exp_attributes = [(Location.mknoloc "tainted", PStr [])];
288288
}
289289

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+
290303
let option_some texp =
291304
let lid = Longident.Lident "Some" in
292305
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
15261539
if vars = [] then end_def ();
15271540
(try unify_pat_types loc !env ty_res record_ty
15281541
with Unify trace ->
1529-
raise
1542+
raise_or_continue
15301543
(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
15441563
in
15451564
let k' k lbl_pat_list =
15461565
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) :
35723591
( l,
35733592
Some
35743593
(if !Clflags.editor_mode then
3575-
try f () with _ -> tainted ()
3594+
try f () with _ -> tainted_expr ()
35763595
else f ()) ))
35773596
(List.rev args),
35783597
instance env (result_type omitted ty_fun) )

0 commit comments

Comments
 (0)