diff --git a/src/analysis/destruct.ml b/src/analysis/destruct.ml index 59bad76b2..00b71ca33 100644 --- a/src/analysis/destruct.ml +++ b/src/analysis/destruct.ml @@ -307,11 +307,8 @@ let rec get_every_pattern loc = function begin match List.find_some ~f:(fun param -> - let open Location in - let param_loc = param.Typedtree.fp_loc in - Lexing.compare_pos loc.loc_start param_loc.loc_start >= 0 - && Lexing.compare_pos param_loc.loc_end loc.loc_end >= 0 - ) params with + Location_aux.included_in param.Typedtree.fp_loc loc + ) params with | Some pattern -> (* In parameter case *) collect_function_pattern loc pattern diff --git a/src/ocaml/parsing/location_aux.ml b/src/ocaml/parsing/location_aux.ml index 966ebdd3f..ef2e8adf2 100644 --- a/src/ocaml/parsing/location_aux.ml +++ b/src/ocaml/parsing/location_aux.ml @@ -46,6 +46,10 @@ let compare_pos pos loc = else 0 +let included_in parent_loc child_loc = +Lexing.compare_pos child_loc.loc_start parent_loc.loc_start >= 0 && + Lexing.compare_pos parent_loc.loc_end child_loc.loc_end >= 0 + let union l1 l2 = if l1 = Location.none then l2 else if l2 = Location.none then l1 diff --git a/src/ocaml/parsing/location_aux.mli b/src/ocaml/parsing/location_aux.mli index 7d99d36a0..c4866ec0b 100644 --- a/src/ocaml/parsing/location_aux.mli +++ b/src/ocaml/parsing/location_aux.mli @@ -42,6 +42,10 @@ val union : t -> t -> t (** Like location_union, but keep loc_ghost'ness of first argument *) val extend : t -> t -> t +(** [included_in parent child] returns [true] if [child] is included + in [parent]. Otherwise returns [false]. *) +val included_in : t -> t -> bool + (** Filter valid errors, log invalid ones *) val prepare_errors : exn list -> Location.error list