Skip to content

Commit

Permalink
Sort errors by location before appending them to the AST
Browse files Browse the repository at this point in the history
This may seem like an unnecessary feature since the whole point
of embedding errors is to allow reporting them all at once. This works
with merlin but not with the compiler which will only report the first
one it encounters.

Signed-off-by: Nathan Rebours <[email protected]>
  • Loading branch information
NathanReb committed Jan 11, 2024
1 parent 1518afc commit 0f527d2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ let print_passes () =
if !perform_checks_on_extensions then
Printf.printf "<builtin:check-unused-extensions>\n")

let sort_errors_by_loc errors =
List.sort errors ~cmp:(fun error error' ->
let loc = Location.Error.get_location error in
let loc' = Location.Error.get_location error' in
Location.compare loc loc')

(*$*)

let map_structure_gen st ~tool_name ~hook ~expect_mismatch_handler ~input_name
Expand All @@ -652,7 +658,8 @@ let map_structure_gen st ~tool_name ~hook ~expect_mismatch_handler ~input_name
st
in
let with_errors errors st =
List.map errors ~f:(fun error ->
let sorted = sort_errors_by_loc errors in
List.map sorted ~f:(fun error ->
Ast_builder.Default.pstr_extension
~loc:(Location.Error.get_location error)
(Location.Error.to_extension error)
Expand Down Expand Up @@ -727,7 +734,8 @@ let map_signature_gen sg ~tool_name ~hook ~expect_mismatch_handler ~input_name
sg
in
let with_errors errors sg =
List.map errors ~f:(fun error ->
let sorted = sort_errors_by_loc errors in
List.map sorted ~f:(fun error ->
Ast_builder.Default.psig_extension
~loc:(Location.Error.get_location error)
(Location.Error.to_extension error)
Expand Down

0 comments on commit 0f527d2

Please sign in to comment.