Skip to content

Commit f197053

Browse files
authored
[Super errors] display type unification more clearly (#1916)
Final part of #1919
1 parent f53802c commit f197053

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

jscomp/super_errors/super_location.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ let super_warning_printer loc ppf w =
117117
end
118118
;;
119119

120+
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/parsing/location.ml#L354 *)
121+
let print_phanton_error_prefix ppf =
122+
(* modified from the original. We use only 2 indentations for error report
123+
(see super_error_reporter above) *)
124+
Format.pp_print_as ppf 2 ""
125+
126+
let errorf ?(loc = none) ?(sub = []) ?(if_highlight = "") fmt =
127+
Location.pp_ksprintf
128+
~before:print_phanton_error_prefix
129+
(fun msg -> {loc; msg; sub; if_highlight})
130+
fmt
131+
132+
let error_of_printer loc print x =
133+
errorf ~loc "%a@?" print x
134+
120135
(* This will be called in super_main. This is how you override the default error and warning printers *)
121136
let setup () =
122137
Location.error_reporter := super_error_reporter;

jscomp/super_errors/super_typecore.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ let report_error env ppf = function
4848
(* modified *)
4949
report_unification_error ppf env trace
5050
(function ppf ->
51-
fprintf ppf "@{<error>This is:@}")
51+
fprintf ppf "This is:")
5252
(function ppf ->
53-
fprintf ppf "@{<info>but somewhere wanted:@}")
53+
fprintf ppf "But somewhere wanted:")
5454
| Apply_non_function typ ->
5555
(* modified *)
5656
reset_and_mark_loops typ;
@@ -239,7 +239,7 @@ let setup () =
239239
Location.register_error_of_exn
240240
(function
241241
| Typecore.Error (loc, env, err) ->
242-
Some (Location.error_of_printer loc (report_error env) err)
242+
Some (Super_location.error_of_printer loc (report_error env) err)
243243
| Typecore.Error_forward err ->
244244
Some err
245245
| _ ->

jscomp/super_errors/super_typetexp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let setup () =
159159
Location.register_error_of_exn
160160
(function
161161
| Typetexp.Error (loc, env, err) ->
162-
Some (Location.error_of_printer loc (report_error env) err)
162+
Some (Super_location.error_of_printer loc (report_error env) err)
163163
(* typetexp doesn't expose Error_forward *)
164164
(* | Error_forward err ->
165165
Some err *)

0 commit comments

Comments
 (0)