Skip to content

Commit db485f1

Browse files
committed
fix #4513
When interface/implementation mismatches, reports the precise location
1 parent 5e2fc8a commit db485f1

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/4.06.1/whole_compiler.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359557,12 +359557,31 @@ let report_error ppf errs =
359557359557
fprintf ppf "@[<v>%a%a@]" print_errs errs include_err err
359558359558

359559359559

359560+
let better_candidate_loc (x : error list) =
359561+
match x with
359562+
| [ (_,_,Interface_mismatch _); (_,_,descr)]
359563+
->
359564+
begin match descr with
359565+
| Value_descriptions (_,d1,_) -> Some d1.val_loc
359566+
| Type_declarations (_,tdcl1,_,_) ->
359567+
Some tdcl1.type_loc
359568+
| Missing_field (_,loc,_) -> Some loc
359569+
| _ -> None
359570+
end
359571+
| _ -> None
359572+
359560359573
(* We could do a better job to split the individual error items
359561359574
as sub-messages of the main interface mismatch on the whole unit. *)
359562359575
let () =
359563359576
Location.register_error_of_exn
359564359577
(function
359565-
| Error err -> Some (Location.error_of_printer_file report_error err)
359578+
| Error err ->
359579+
begin match better_candidate_loc err with
359580+
| None ->
359581+
Some (Location.error_of_printer_file report_error err)
359582+
| Some loc ->
359583+
Some (Location.error_of_printer loc report_error err)
359584+
end
359566359585
| _ -> None
359567359586
)
359568359587

ocaml

0 commit comments

Comments
 (0)