@@ -6,8 +6,12 @@ open Typedtree
6
6
open Btype
7
7
open Ctype
8
8
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
11
15
12
16
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/typing/typecore.ml#L3769 *)
13
17
(* modified branches are commented *)
@@ -21,20 +25,20 @@ let report_error env ppf = function
21
25
" @[This variant constructor, %a, expects %i %s; here, we've %sfound %i.@]"
22
26
longident lid expected (if expected == 1 then " argument" else " arguments" ) (if provided < expected then " only " else " " ) provided
23
27
| Label_mismatch (lid , trace ) ->
24
- report_unification_error ppf env trace
28
+ super_report_unification_error ppf env trace
25
29
(function ppf ->
26
30
fprintf ppf " The record field %a@ belongs to the type"
27
31
longident lid)
28
32
(function ppf ->
29
33
fprintf ppf " but is mixed here with fields of type" )
30
34
| Pattern_type_clash trace ->
31
- report_unification_error ppf env trace
35
+ super_report_unification_error ppf env trace
32
36
(function ppf ->
33
37
fprintf ppf " This pattern matches values of type" )
34
38
(function ppf ->
35
39
fprintf ppf " but a pattern was expected which matches values of type" )
36
40
| Or_pattern_type_clash (id , trace ) ->
37
- report_unification_error ppf env trace
41
+ super_report_unification_error ppf env trace
38
42
(function ppf ->
39
43
fprintf ppf " The variable %s on the left-hand side of this or-pattern has type" (Ident. name id))
40
44
(function ppf ->
@@ -58,7 +62,7 @@ let report_error env ppf = function
58
62
If so, please use `ReasonReact.createDomElement`:@ https://reasonml.github.io/reason-react/index.html#reason-react-working-with-children@]@,@,\
59
63
@[@{<info>Here's the original error message@}@]@,\
60
64
@]" ;
61
- report_unification_error ppf env trace
65
+ super_report_unification_error ppf env trace
62
66
(function ppf ->
63
67
fprintf ppf " This is:" )
64
68
(function ppf ->
@@ -116,7 +120,7 @@ let report_error env ppf = function
116
120
else Constructor.spellcheck ppf env p lid *)
117
121
| Name_type_mismatch (kind , lid , tp , tpl ) ->
118
122
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
120
124
(function ppf ->
121
125
fprintf ppf " The %s %a@ belongs to the %s type"
122
126
name longident lid kind)
@@ -146,18 +150,18 @@ let report_error env ppf = function
146
150
else
147
151
fprintf ppf " The value %s is not an instance variable" v
148
152
| 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
150
154
| Outside_class ->
151
155
fprintf ppf " This object duplication occurs outside a method definition"
152
156
| Value_multiply_overridden v ->
153
157
fprintf ppf " The instance variable %s is overridden several times" v
154
158
| Coercion_failure (ty , ty' , trace , b ) ->
155
- report_unification_error ppf env trace
159
+ super_report_unification_error ppf env trace
156
160
(function ppf ->
157
- let ty, ty' = prepare_expansion (ty, ty') in
161
+ let ty, ty' = Printtyp. prepare_expansion (ty, ty') in
158
162
fprintf ppf
159
163
" This expression cannot be coerced to type@;<1 2>%a;@ it has type"
160
- (type_expansion ty) ty')
164
+ (Printtyp. type_expansion ty) ty')
161
165
(function ppf ->
162
166
fprintf ppf " but is here used with type" );
163
167
if b then
@@ -206,7 +210,7 @@ let report_error env ppf = function
206
210
fprintf ppf " in an order different from other calls.@ " ;
207
211
fprintf ppf " This is only allowed when the real type is known."
208
212
| Less_general (kind , trace ) ->
209
- report_unification_error ppf env trace
213
+ super_report_unification_error ppf env trace
210
214
(fun ppf -> fprintf ppf " This %s has type" kind)
211
215
(fun ppf -> fprintf ppf " which is less general than" )
212
216
| Modules_not_allowed ->
@@ -219,7 +223,7 @@ let report_error env ppf = function
219
223
" This expression is packed module, but the expected type is@ %a"
220
224
type_expr ty
221
225
| Recursive_local_constraint trace ->
222
- report_unification_error ppf env trace
226
+ super_report_unification_error ppf env trace
223
227
(function ppf ->
224
228
fprintf ppf " Recursive local constraint when unifying" )
225
229
(function ppf ->
@@ -229,7 +233,7 @@ let report_error env ppf = function
229
233
" Unexpected existential"
230
234
| Unqualified_gadt_pattern (tpath , name ) ->
231
235
fprintf ppf " @[The GADT constructor %s of type %a@ %s.@]"
232
- name path tpath
236
+ name Printtyp. path tpath
233
237
" must be qualified in this pattern"
234
238
| Invalid_interval ->
235
239
fprintf ppf " @[Only character intervals are supported in patterns.@]"
@@ -244,7 +248,7 @@ let report_error env ppf = function
244
248
" @[Exception patterns must be at the top level of a match case.@]"
245
249
246
250
let 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)
248
252
249
253
(* 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 *)
250
254
let setup () =
0 commit comments