Skip to content

Commit cdbed51

Browse files
committed
handle locs in arg labels in a more robust way
1 parent ae2ec92 commit cdbed51

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

compiler/ml/typecore.ml

+12-15
Original file line numberDiff line numberDiff line change
@@ -2280,9 +2280,9 @@ let not_function env ty =
22802280
ls = [] && not tvar
22812281
22822282
type lazy_args =
2283-
(Asttypes.Noloc.arg_label * (unit -> Typedtree.expression) option) list
2283+
(Asttypes.arg_label * (unit -> Typedtree.expression) option) list
22842284
2285-
type targs = (Asttypes.Noloc.arg_label * Typedtree.expression option) list
2285+
type targs = (Asttypes.arg_label * Typedtree.expression option) list
22862286
let rec type_exp ?recarg env sexp =
22872287
(* We now delegate everything to type_expect *)
22882288
type_expect ?recarg env sexp (newvar ())
@@ -2473,9 +2473,6 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
24732473
end_def ();
24742474
unify_var env (newvar ()) funct.exp_type;
24752475
2476-
let args_with_loc =
2477-
List.map2 (fun (sarg, _) (_, label_exp) -> (sarg, label_exp)) sargs args
2478-
in
24792476
let mk_apply funct args =
24802477
rue
24812478
{
@@ -2494,8 +2491,8 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
24942491
| _ -> false
24952492
in
24962493
2497-
if fully_applied && not is_primitive then rue (mk_apply funct args_with_loc)
2498-
else rue (mk_apply funct args_with_loc)
2494+
if fully_applied && not is_primitive then rue (mk_apply funct args)
2495+
else rue (mk_apply funct args)
24992496
| Pexp_match (sarg, caselist) ->
25002497
begin_def ();
25012498
let arg = type_exp env sarg in
@@ -3448,7 +3445,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
34483445
unify env lhs_type (instance_def Predef.type_int);
34493446
instance_def Predef.type_int
34503447
in
3451-
let targs = [(to_noloc lhs_label, Some lhs)] in
3448+
let targs = [(lhs_label, Some lhs)] in
34523449
Some (targs, result_type)
34533450
| ( Some {form = Binary; specialization},
34543451
[(lhs_label, lhs_expr); (rhs_label, rhs_expr)] ) ->
@@ -3506,9 +3503,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
35063503
let rhs = type_expect env rhs_expr Predef.type_int in
35073504
(lhs, rhs, instance_def Predef.type_int))
35083505
in
3509-
let targs =
3510-
[(to_noloc lhs_label, Some lhs); (to_noloc rhs_label, Some rhs)]
3511-
in
3506+
let targs = [(lhs_label, Some lhs); (rhs_label, Some rhs)] in
35123507
Some (targs, result_type)
35133508
| _ -> None)
35143509
| _ -> None
@@ -3607,7 +3602,7 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
36073602
| Tarrow (Optional l, t1, t2, _, _) ->
36083603
ignored := (Noloc.Optional l, t1, ty_fun.level) :: !ignored;
36093604
let arg =
3610-
( Noloc.Optional l,
3605+
( to_arg_label (Optional l),
36113606
Some (fun () -> option_none (instance env t1) Location.none) )
36123607
in
36133608
type_unknown_args max_arity ~args:(arg :: args) ~top_arity:None
@@ -3667,7 +3662,8 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
36673662
if optional then unify_exp env arg1 (type_option (newvar ()));
36683663
arg1
36693664
in
3670-
type_unknown_args max_arity ~args:((l1, Some arg1) :: args)
3665+
type_unknown_args max_arity
3666+
~args:((to_arg_label l1, Some arg1) :: args)
36713667
~top_arity:None omitted ty2 sargl
36723668
in
36733669
let rec type_args ?type_clash_context max_arity args omitted ~ty_fun ty_fun0
@@ -3706,8 +3702,9 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
37063702
(extract_option_type env ty)
37073703
(extract_option_type env ty0))) )
37083704
in
3709-
type_args ?type_clash_context max_arity ((l, arg) :: args) omitted ~ty_fun
3710-
ty_fun0 ~sargs ~top_arity
3705+
type_args ?type_clash_context max_arity
3706+
((to_arg_label l, arg) :: args)
3707+
omitted ~ty_fun ty_fun0 ~sargs ~top_arity
37113708
| _ ->
37123709
type_unknown_args max_arity ~args ~top_arity omitted ty_fun0
37133710
sargs (* This is the hot path for non-labeled function*)

0 commit comments

Comments
 (0)