@@ -6,8 +6,12 @@ open Typedtree
66open Btype
77open Ctype
88
9- open Format
10- open Printtyp
9+ let fprintf = Format. fprintf
10+ let sprintf = Format. sprintf
11+ let longident = Printtyp. longident
12+ let super_report_unification_error = Printtyp. super_report_unification_error
13+ let reset_and_mark_loops = Printtyp. reset_and_mark_loops
14+ let type_expr = Printtyp. type_expr
1115
1216(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/typing/typecore.ml#L3769 *)
1317(* modified branches are commented *)
@@ -21,20 +25,20 @@ let report_error env ppf = function
2125 " @[This variant constructor, %a, expects %i %s; here, we've %sfound %i.@]"
2226 longident lid expected (if expected == 1 then " argument" else " arguments" ) (if provided < expected then " only " else " " ) provided
2327 | Label_mismatch (lid , trace ) ->
24- report_unification_error ppf env trace
28+ super_report_unification_error ppf env trace
2529 (function ppf ->
2630 fprintf ppf " The record field %a@ belongs to the type"
2731 longident lid)
2832 (function ppf ->
2933 fprintf ppf " but is mixed here with fields of type" )
3034 | Pattern_type_clash trace ->
31- report_unification_error ppf env trace
35+ super_report_unification_error ppf env trace
3236 (function ppf ->
3337 fprintf ppf " This pattern matches values of type" )
3438 (function ppf ->
3539 fprintf ppf " but a pattern was expected which matches values of type" )
3640 | Or_pattern_type_clash (id , trace ) ->
37- report_unification_error ppf env trace
41+ super_report_unification_error ppf env trace
3842 (function ppf ->
3943 fprintf ppf " The variable %s on the left-hand side of this or-pattern has type" (Ident. name id))
4044 (function ppf ->
@@ -58,7 +62,7 @@ let report_error env ppf = function
5862 If so, please use `ReasonReact.createDomElement`:@ https://reasonml.github.io/reason-react/index.html#reason-react-working-with-children@]@,@,\
5963 @[@{<info>Here's the original error message@}@]@,\
6064 @]" ;
61- report_unification_error ppf env trace
65+ super_report_unification_error ppf env trace
6266 (function ppf ->
6367 fprintf ppf " This is:" )
6468 (function ppf ->
@@ -116,7 +120,7 @@ let report_error env ppf = function
116120 else Constructor.spellcheck ppf env p lid *)
117121 | Name_type_mismatch (kind , lid , tp , tpl ) ->
118122 let name = if kind = " record" then " field" else " constructor" in
119- report_ambiguous_type_error ppf env tp tpl
123+ Printtyp. report_ambiguous_type_error ppf env tp tpl
120124 (function ppf ->
121125 fprintf ppf " The %s %a@ belongs to the %s type"
122126 name longident lid kind)
@@ -146,18 +150,18 @@ let report_error env ppf = function
146150 else
147151 fprintf ppf " The value %s is not an instance variable" v
148152 | Not_subtype (tr1 , tr2 ) ->
149- report_subtyping_error ppf env tr1 " is not a subtype of" tr2
153+ Printtyp. report_subtyping_error ppf env tr1 " is not a subtype of" tr2
150154 | Outside_class ->
151155 fprintf ppf " This object duplication occurs outside a method definition"
152156 | Value_multiply_overridden v ->
153157 fprintf ppf " The instance variable %s is overridden several times" v
154158 | Coercion_failure (ty , ty' , trace , b ) ->
155- report_unification_error ppf env trace
159+ super_report_unification_error ppf env trace
156160 (function ppf ->
157- let ty, ty' = prepare_expansion (ty, ty') in
161+ let ty, ty' = Printtyp. prepare_expansion (ty, ty') in
158162 fprintf ppf
159163 " This expression cannot be coerced to type@;<1 2>%a;@ it has type"
160- (type_expansion ty) ty')
164+ (Printtyp. type_expansion ty) ty')
161165 (function ppf ->
162166 fprintf ppf " but is here used with type" );
163167 if b then
@@ -206,7 +210,7 @@ let report_error env ppf = function
206210 fprintf ppf " in an order different from other calls.@ " ;
207211 fprintf ppf " This is only allowed when the real type is known."
208212 | Less_general (kind , trace ) ->
209- report_unification_error ppf env trace
213+ super_report_unification_error ppf env trace
210214 (fun ppf -> fprintf ppf " This %s has type" kind)
211215 (fun ppf -> fprintf ppf " which is less general than" )
212216 | Modules_not_allowed ->
@@ -219,7 +223,7 @@ let report_error env ppf = function
219223 " This expression is packed module, but the expected type is@ %a"
220224 type_expr ty
221225 | Recursive_local_constraint trace ->
222- report_unification_error ppf env trace
226+ super_report_unification_error ppf env trace
223227 (function ppf ->
224228 fprintf ppf " Recursive local constraint when unifying" )
225229 (function ppf ->
@@ -229,7 +233,7 @@ let report_error env ppf = function
229233 " Unexpected existential"
230234 | Unqualified_gadt_pattern (tpath , name ) ->
231235 fprintf ppf " @[The GADT constructor %s of type %a@ %s.@]"
232- name path tpath
236+ name Printtyp. path tpath
233237 " must be qualified in this pattern"
234238 | Invalid_interval ->
235239 fprintf ppf " @[Only character intervals are supported in patterns.@]"
@@ -244,7 +248,7 @@ let report_error env ppf = function
244248 " @[Exception patterns must be at the top level of a match case.@]"
245249
246250let report_error env ppf err =
247- wrap_printing_env env (fun () -> report_error env ppf err)
251+ Printtyp. wrap_printing_env env (fun () -> report_error env ppf err)
248252
249253(* This will be called in super_main. This is how you'd override the default error printer from the compiler & register new error_of_exn handlers *)
250254let setup () =
0 commit comments