pass a proper location to Matching.for_trywith

Actually *using* the location in the failure handler would be
incorrect, as it adds noise to backtraces involving partial exception
handlers. This is now properly documented.

We still take the caller location (which is currently ignored) for
consistency with other toplevel Matching functions, and because that
may become useful if we want to add more error-reporting or warnings
in compile_matching.
master
Gabriel Scherer 2020-06-06 15:23:58 +02:00
parent cfe6a50533
commit 6aeed1c84d
3 changed files with 14 additions and 5 deletions

View File

@ -3391,9 +3391,18 @@ let for_function ~scopes loc repr param pat_act_list partial =
compile_matching ~scopes repr f param pat_act_list partial
(* In the following two cases, exhaustiveness info is not available! *)
let for_trywith ~scopes param pat_act_list =
let for_trywith ~scopes loc param pat_act_list =
(* Note: the failure action of [for_trywith] corresponds
to an exception that is not matched by a try..with handler,
and is thus reraised for the next handler in the stack.
It is important to *not* include location information in
the reraise (hence the [Loc_unknown]) to avoid seeing this
silent reraise in exception backtraces. *)
compile_matching ~scopes None
(fun () -> Lprim (Praise Raise_reraise, [ param ], Loc_unknown))
(fun () ->
ignore loc;
Lprim (Praise Raise_reraise, [ param ], Loc_unknown))
param pat_act_list Partial
let simple_for_let ~scopes loc param pat body =

View File

@ -25,7 +25,7 @@ val for_function:
int ref option -> lambda -> (pattern * lambda) list -> partial ->
lambda
val for_trywith:
scopes:scopes ->
scopes:scopes -> Location.t ->
lambda -> (pattern * lambda) list ->
lambda
val for_let:

View File

@ -292,7 +292,7 @@ and transl_exp0 ~scopes e =
| Texp_try(body, pat_expr_list) ->
let id = Typecore.name_cases "exn" pat_expr_list in
Ltrywith(transl_exp ~scopes body, id,
Matching.for_trywith ~scopes (Lvar id)
Matching.for_trywith ~scopes e.exp_loc (Lvar id)
(transl_cases_try ~scopes pat_expr_list))
| Texp_tuple el ->
let ll, shape = transl_list_with_shape ~scopes el in
@ -1035,7 +1035,7 @@ and transl_match ~scopes e arg pat_expr_list partial =
let static_exception_id = next_raise_count () in
Lstaticcatch
(Ltrywith (Lstaticraise (static_exception_id, body), id,
Matching.for_trywith ~scopes (Lvar id) exn_cases),
Matching.for_trywith ~scopes e.exp_loc (Lvar id) exn_cases),
(static_exception_id, val_ids),
handler)
in