···274274- #13255: Re-enable warning 34 for unused locally abstract types
275275 (Nick Roberts, review by Chris Casinghino and Florian Angeletti)
276276277277+- #12182: Improve the type clash error message.
278278+ For example, this message:
279279+ This expression has type ...
280280+ is changed into:
281281+ The constant "42" has type ...
282282+ (Jules Aguillon, review by Gabriel Scherer and Florian Angeletti)
283283+277284### Internal/compiler-libs changes:
278285279286- #11129, #11148: enforce that ppxs do not produce `parsetree`s with
+42
parsing/pprintast.ml
···136136137137 let tyvar ppf s =
138138 Format_doc.fprintf ppf "%s" (tyvar_of_name s)
139139+140140+ (* Expressions are considered nominal if they can be used as the subject of a
141141+ sentence or action. In practice, we consider that an expression is nominal
142142+ if they satisfy one of:
143143+ - Similar to an identifier: words separated by '.' or '#'.
144144+ - Do not contain spaces when printed.
145145+ - Is a constant that is short enough.
146146+ *)
147147+ let nominal_exp t =
148148+ let open Format_doc.Doc in
149149+ let longident l = Format_doc.doc_printer longident l.Location.txt in
150150+ let rec nominal_exp doc exp =
151151+ match exp.pexp_desc with
152152+ | _ when exp.pexp_attributes <> [] -> None
153153+ | Pexp_ident l ->
154154+ Some (longident l doc)
155155+ | Pexp_variant (lbl, None) ->
156156+ Some (printf "`%s" lbl doc)
157157+ | Pexp_construct (l, None) ->
158158+ Some (longident l doc)
159159+ | Pexp_field (parent, lbl) ->
160160+ Option.map
161161+ (printf ".%t" (longident lbl))
162162+ (nominal_exp doc parent)
163163+ | Pexp_send (parent, meth) ->
164164+ Option.map
165165+ (printf "#%s" meth.txt)
166166+ (nominal_exp doc parent)
167167+ (* String constants are syntactically too complex. For example, the
168168+ quotes conflict with the 'inline_code' style and they might contain
169169+ spaces. *)
170170+ | Pexp_constant { pconst_desc = Pconst_string _; _ } -> None
171171+ (* Char, integer and float constants are nominal. *)
172172+ | Pexp_constant { pconst_desc = Pconst_char c; _ } ->
173173+ Some (msg "%C" c)
174174+ | Pexp_constant
175175+ { pconst_desc = Pconst_integer (cst, suf) | Pconst_float (cst, suf);
176176+ _ } ->
177177+ Some (msg "%s%t" cst (option char suf))
178178+ | _ -> None
179179+ in
180180+ nominal_exp empty t
139181end
140182141183let longident ppf l = Format_doc.compat Doc.longident ppf l
+4
parsing/pprintast.mli
···6464module Doc:sig
6565 val longident: Longident.t Format_doc.printer
6666 val tyvar: string Format_doc.printer
6767+6868+ (** Returns a format document if the expression reads nicely as the subject
6969+ of a sentence in a error message. *)
7070+ val nominal_exp : Parsetree.expression -> Format_doc.t option
6771end
+2-2
testsuite/tests/effect-syntax/error_messages.ml
···2424Line 3, characters 21-22:
25253 | | effect A _, k -> k
2626 ^
2727-Error: This expression has type "(%eff, unit) continuation"
2727+Error: The value "k" has type "(%eff, unit) continuation"
2828 but an expression was expected of type "unit"
2929|}, Principal{|
3030Line 3, characters 21-22:
31313 | | effect A _, k -> k
3232 ^
3333-Error: This expression has type "(int, unit) continuation"
3333+Error: The value "k" has type "(int, unit) continuation"
3434 but an expression was expected of type "unit"
3535 This instance of "int" is ambiguous:
3636 it would escape the scope of its equation
···11Line 2, characters 4-9:
222 | 1 + "foo";;
33 ^^^^^
44-Error: This expression has type
44+Error: This constant has type
55 "string"
66 but an expression was expected of type
77 "int"
88Line 2, characters 4-9:
992 | 1 + "foo";;
1010 ^^^^^
1111-Error: This expression has type "string" but an expression was expected of type
1212- "int"
1111+Error: This constant has type "string" but an expression was expected of type "int"
1312
+1-1
testsuite/tests/generalized-open/gpr1506.ml
···360360Line 1, characters 42-43:
3613611 | let x = let open struct type t = T end in T
362362 ^
363363-Error: This expression has type "t" but an expression was expected of type "'a"
363363+Error: The constructor "T" has type "t" but an expression was expected of type "'a"
364364 The type constructor "t" would escape its scope
365365|}]
366366
···11File "libc/c1.ml", line 1, characters 8-11:
221 | let x = B.x + 1
33 ^^^
44-Error: This expression has type "A.t" but an expression was expected of type
55- "int"
44+Error: The value "B.x" has type "A.t" but an expression was expected of type "int"
65 Type "A.t" is abstract because no corresponding cmi file was found
76 in path.
+2-2
testsuite/tests/let-syntax/let_syntax.ml
···187187Line 3, characters 13-14:
1881883 | let+ x = 1 in
189189 ^
190190-Error: This expression has type "int" but an expression was expected of type
190190+Error: The constant "1" has type "int" but an expression was expected of type
191191 "bool"
192192|}];;
193193···215215Line 3, characters 13-14:
2162163 | let+ x = 1
217217 ^
218218-Error: This expression has type "int" but an expression was expected of type
218218+Error: The constant "1" has type "int" but an expression was expected of type
219219 "float"
220220 Hint: Did you mean "1."?
221221|}];;
+3-3
testsuite/tests/printing-types/existentials.ml
···1515Line 6, characters 13-14:
16166 | | Foo a -> a + 1
1717 ^
1818-Error: This expression has type "$a * $b * $c * $d * $e * $f"
1818+Error: The value "a" has type "$a * $b * $c * $d * $e * $f"
1919 but an expression was expected of type "int"
2020 Hint: "$a", "$b", "$c", "$d", "$e" and "$f" are existential types
2121 bound by the constructor "Foo".
···4848Line 13, characters 46-47:
494913 | let x = (a1, a2, a3, a4, a5, a6, a7) in x + 1
5050 ^
5151-Error: This expression has type "$a * $a1 * $a2 * $a3 * $a4 * $a5 * $a6"
5151+Error: The value "x" has type "$a * $a1 * $a2 * $a3 * $a4 * $a5 * $a6"
5252 but an expression was expected of type "int"
5353 Hint: "$a" is an existential type bound by the constructor "Foo1".
5454 Hint: "$a1" is an existential type bound by the constructor "Foo2".
···8686Line 13, characters 46-47:
878713 | let x = (a1, a2, a3, a4, a5, a6, a7) in x + 1
8888 ^
8989-Error: This expression has type
8989+Error: The value "x" has type
9090 "($a * $b * $c * $d * $e * $f) *
9191 ($a1 * $b1 * $c1 * $d1 * $e1 * $f1) *
9292 ($a2 * $b2 * $c2 * $d2 * $e2 * $f2) *
···99$\?$ 1 + <<2.>> ;;
1010\end{camlinput}
1111\begin{camlerror}
1212-Error: This expression has type float but an expression was expected of type
1212+Error: The constant 2. has type float but an expression was expected of type
1313 int
1414\end{camlerror}
1515\end{caml}
+2-2
testsuite/tests/tool-expect-test/clean_typer.ml
···6464Line 1, characters 14-17:
65651 | let f2 = ffoo bar;;
6666 ^^^
6767-Error: This expression has type "Variants.bar M.t"
6767+Error: The value "bar" has type "Variants.bar M.t"
6868 but an expression was expected of type "Variants.foo M.t"
6969 Type "Variants.bar" = "[ `Bar ]" is not compatible with type "Variants.foo"
7070 The first variant type does not allow tag(s) "`Foo"
···7575Line 1, characters 14-17:
76761 | let f3 = fbar foo;;
7777 ^^^
7878-Error: This expression has type "Variants.foo M.t"
7878+Error: The value "foo" has type "Variants.foo M.t"
7979 but an expression was expected of type "Variants.bar M.t"
8080 Type "Variants.foo" is not compatible with type "Variants.bar" = "[ `Bar ]"
8181 The second variant type does not allow tag(s) "`Foo"
···11File "foo.ml", line 1, characters 14-18:
221 | let x : int = true
33 ^^^^
44-Error: This expression has type "bool" but an expression was expected of type
55- "int"
44+Error: The constructor "\#true" has type "bool"
55+ but an expression was expected of type "int"
···2222Line 3, characters 8-9:
23233 | let y = 1 +. 2. in
2424 ^
2525-Error: This expression has type "int" but an expression was expected of type
2525+Error: The constant "1" has type "int" but an expression was expected of type
2626 "float"
2727 Hint: Did you mean "1."?
2828Line 4, characters 2-4:
···4242Line 2, characters 12-17:
43432 | let x = 1 + "abc" in
4444 ^^^^^
4545-Error: This expression has type "string" but an expression was expected of type
4545+Error: This constant has type "string" but an expression was expected of type
4646 "int"
4747File "error_highlighting_use1.ml", line 1, characters 8-15:
48481 | let x = (1 + 2) +. 3. in ();;
···2121Line 2, characters 16-20:
22222 | 11;; let x = 12+true;; 13;; (* Type error in second phrase. *)
2323 ^^^^
2424-Error: This expression has type "bool" but an expression was expected of type
2525- "int"
2424+Error: The constructor "\#true" has type "bool"
2525+ but an expression was expected of type "int"
2626# Line 2, characters 0-22:
27272 | match 14 with 15 -> ();; 16;; 17;; (* Warning + run-time error in 1st phrase. *)
2828 ^^^^^^^^^^^^^^^^^^^^^^
···1414Line 2, characters 4-5:
15152 | x = y;;
1616 ^
1717-Error: This expression has type "(u * v * (module S)) M.t"
1717+Error: The value "y" has type "(u * v * (module S)) M.t"
1818 but an expression was expected of type
1919 "(u/2 * v/2 * (module S/2)) M/2.t"
2020 Hint: The types "v" and "u" have been defined multiple times in this
···3535Line 2, characters 4-5:
36362 | a = b;;
3737 ^
3838-Error: This expression has type "a/2" but an expression was expected of type
3939- "a/3"
3838+Error: The value "b" has type "a/2" but an expression was expected of type "a/3"
4039 Hint: The type "a" has been defined multiple times in this toplevel
4140 session. Some toplevel values still refer to old versions of this
4241 type. Did you try to redefine them?
4342Line 1, characters 4-5:
44431 | a = c;;
4544 ^
4646-Error: This expression has type "a" but an expression was expected of type "a/3"
4545+Error: The value "c" has type "a" but an expression was expected of type "a/3"
4746 Hint: The type "a" has been defined multiple times in this toplevel
4847 session. Some toplevel values still refer to old versions of this
4948 type. Did you try to redefine them?
5049Line 1, characters 4-5:
51501 | b = c;;
5251 ^
5353-Error: This expression has type "a" but an expression was expected of type "a/2"
5252+Error: The value "c" has type "a" but an expression was expected of type "a/2"
5453 Hint: The type "a" has been defined multiple times in this toplevel
5554 session. Some toplevel values still refer to old versions of this
5655 type. Did you try to redefine them?
+1-1
testsuite/tests/tool-toplevel/use_command.ml
···2020File "(command-output)", line 1, characters 5-6:
21211 | 1 :: x
2222 ^
2323-Error: This expression has type "int" but an expression was expected of type
2323+Error: The value "x" has type "int" but an expression was expected of type
2424 "int list"
2525|}];;
···77Line 1, characters 19-20:
881 | let _ = Int32.(add 1 2l);;
99 ^
1010-Error: This expression has type "int" but an expression was expected of type
1010+Error: The constant "1" has type "int" but an expression was expected of type
1111 "int32"
1212 Hint: Did you mean "1l"?
1313|}]
···1717Line 1, characters 29-31:
18181 | let _ : int32 * int32 = 42l, 43;;
1919 ^^
2020-Error: This expression has type "int" but an expression was expected of type
2020+Error: The constant "43" has type "int" but an expression was expected of type
2121 "int32"
2222 Hint: Did you mean "43l"?
2323|}]
···2727Line 1, characters 33-35:
28281 | let _ : int32 * nativeint = 42l, 43;;
2929 ^^
3030-Error: This expression has type "int" but an expression was expected of type
3030+Error: The constant "43" has type "int" but an expression was expected of type
3131 "nativeint"
3232 Hint: Did you mean "43n"?
3333|}]
···3737Line 1, characters 15-16:
38381 | let _ = min 6L 7;;
3939 ^
4040-Error: This expression has type "int" but an expression was expected of type
4040+Error: The constant "7" has type "int" but an expression was expected of type
4141 "int64"
4242 Hint: Did you mean "7L"?
4343|}]
···4747Line 1, characters 16-19:
48481 | let _ : float = 123;;
4949 ^^^
5050-Error: This expression has type "int" but an expression was expected of type
5050+Error: The constant "123" has type "int" but an expression was expected of type
5151 "float"
5252 Hint: Did you mean "123."?
5353|}]
···6060Line 2, characters 19-20:
61612 | let _ = Int32.(add x 2l);;
6262 ^
6363-Error: This expression has type "int" but an expression was expected of type
6464- "int32"
6363+Error: The value "x" has type "int" but an expression was expected of type "int32"
6564|}]
66656766(* pattern *)
···9594Line 1, characters 16-18:
96951 | let _ : int32 = 1L;;
9796 ^^
9898-Error: This expression has type "int64" but an expression was expected of type
9797+Error: The constant "1L" has type "int64" but an expression was expected of type
9998 "int32"
10099 Hint: Did you mean "1l"?
101100|}]
···104103Line 1, characters 16-18:
1051041 | let _ : float = 1L;;
106105 ^^
107107-Error: This expression has type "int64" but an expression was expected of type
106106+Error: The constant "1L" has type "int64" but an expression was expected of type
108107 "float"
109108 Hint: Did you mean "1."?
110109|}]
···113112Line 1, characters 16-18:
1141131 | let _ : int64 = 1n;;
115114 ^^
116116-Error: This expression has type "nativeint"
115115+Error: The constant "1n" has type "nativeint"
117116 but an expression was expected of type "int64"
118117 Hint: Did you mean "1L"?
119118|}]
···122121Line 1, characters 20-22:
1231221 | let _ : nativeint = 1l;;
124123 ^^
125125-Error: This expression has type "int32" but an expression was expected of type
124124+Error: The constant "1l" has type "int32" but an expression was expected of type
126125 "nativeint"
127126 Hint: Did you mean "1n"?
128127|}]
···133132Line 1, characters 16-18:
1341331 | let _ : int64 = 0.;;
135134 ^^
136136-Error: This expression has type "float" but an expression was expected of type
135135+Error: The constant "0." has type "float" but an expression was expected of type
137136 "int64"
138137|}]
139138let _ : int = 1L;;
···141140Line 1, characters 14-16:
1421411 | let _ : int = 1L;;
143142 ^^
144144-Error: This expression has type "int64" but an expression was expected of type
143143+Error: The constant "1L" has type "int64" but an expression was expected of type
145144 "int"
146145|}]
147146···152151Line 1, characters 23-28:
1531521 | let _ : int64 = min 0L 1_000;;
154153 ^^^^^
155155-Error: This expression has type "int" but an expression was expected of type
154154+Error: The constant "1_000" has type "int" but an expression was expected of type
156155 "int64"
157156 Hint: Did you mean "1_000L"?
158157|}]
···161160Line 1, characters 36-44:
1621611 | let _ : nativeint * nativeint = 0n, 0xAA_BBL;;
163162 ^^^^^^^^
164164-Error: This expression has type "int64" but an expression was expected of type
165165- "nativeint"
163163+Error: The constant "0xAA_BBL" has type "int64"
164164+ but an expression was expected of type "nativeint"
166165 Hint: Did you mean "0xAA_BBn"?
167166|}]
168167let _ : int32 -> int32 = function
···193192Line 1, characters 49-55:
1941931 | type t1 = {f1: int32};; let _ = fun x -> x.f1 <- 1_000n;;
195194 ^^^^^^
196196-Error: This expression has type "nativeint"
195195+Error: The constant "1_000n" has type "nativeint"
197196 but an expression was expected of type "int32"
198197 Hint: Did you mean "1_000l"?
199198|}]
···99Line 1, characters 3-4:
10101 | if 3 then ();;
1111 ^
1212-Error: This expression has type "int" but an expression was expected of type
1212+Error: The constant "3" has type "int" but an expression was expected of type
1313 "bool"
1414 because it is in the condition of an if-statement
1515|}];;
···2020Line 1, characters 45-46:
21211 | fun b -> if true then (print_int b) else (if b then ());;
2222 ^
2323-Error: This expression has type "int" but an expression was expected of type
2424- "bool"
2525- because it is in the condition of an if-statement
2323+Error: The value "b" has type "int" but an expression was expected of type "
2424+ bool" because it is in the condition of an if-statement
2625|}];;
27262827(* Left-to-right bias is still there: if we swap the branches, the new error
···3332Line 1, characters 53-54:
34331 | fun b -> if true then (if b then ()) else (print_int b);;
3534 ^
3636-Error: This expression has type "bool" but an expression was expected of type
3737- "int"
3535+Error: The value "b" has type "bool" but an expression was expected of type "int"
3836|}];;
39374038if (let x = 3 in x) then ();;
···4341Line 1, characters 17-18:
44421 | if (let x = 3 in x) then ();;
4543 ^
4646-Error: This expression has type "int" but an expression was expected of type
4747- "bool"
4848- because it is in the condition of an if-statement
4444+Error: The value "x" has type "int" but an expression was expected of type "
4545+ bool" because it is in the condition of an if-statement
4946|}];;
50475148if (if true then 3 else 4) then ();;
···5451Line 1, characters 17-18:
55521 | if (if true then 3 else 4) then ();;
5653 ^
5757-Error: This expression has type "int" but an expression was expected of type
5454+Error: The constant "3" has type "int" but an expression was expected of type
5855 "bool"
5956 because it is in the condition of an if-statement
6057|}];;
···6562Line 1, characters 13-14:
66631 | if true then 3;;
6764 ^
6868-Error: This expression has type "int" but an expression was expected of type
6565+Error: The constant "3" has type "int" but an expression was expected of type
6966 "unit"
7067 because it is in the result of a conditional with no else branch
7168|}];;
···8683Line 1, characters 6-8:
87841 | while 42 do () done;;
8885 ^^
8989-Error: This expression has type "int" but an expression was expected of type
8686+Error: The constant "42" has type "int" but an expression was expected of type
9087 "bool"
9188 because it is in the condition of a while-loop
9289|}];;
···9996Line 1, characters 14-37:
100971 | while true do (if true then 3 else 4) done;;
10198 ^^^^^^^^^^^^^^^^^^^^^^^
102102-Error: This expression has type "int" but an expression was expected of type
103103- "unit"
9999+Error: This "if-then-else" expression has type "int"
100100+ but an expression was expected of type "unit"
104101 because it is in the body of a while-loop
105102|}];;
106103···110107Line 1, characters 8-10:
1111081 | for i = 3. to 4 do () done;;
112109 ^^
113113-Error: This expression has type "float" but an expression was expected of type
110110+Error: The constant "3." has type "float" but an expression was expected of type
114111 "int"
115112 because it is in a for-loop start index
116113|}];;
···121118Line 1, characters 13-15:
1221191 | for i = 3 to 4. do () done;;
123120 ^^
124124-Error: This expression has type "float" but an expression was expected of type
121121+Error: The constant "4." has type "float" but an expression was expected of type
125122 "int"
126123 because it is in a for-loop stop index
127124|}];;
···134131Line 1, characters 18-41:
1351321 | for i = 0 to 0 do (if true then 3 else 4) done;;
136133 ^^^^^^^^^^^^^^^^^^^^^^^
137137-Error: This expression has type "int" but an expression was expected of type
138138- "unit"
134134+Error: This "if-then-else" expression has type "int"
135135+ but an expression was expected of type "unit"
139136 because it is in the body of a for-loop
140137|}];;
141138···145142Line 1, characters 7-9:
1461431 | assert 12;;
147144 ^^
148148-Error: This expression has type "int" but an expression was expected of type
145145+Error: The constant "12" has type "int" but an expression was expected of type
149146 "bool"
150147 because it is in the condition of an assertion
151148|}];;
···1111Line 2, characters 10-11:
12122 | let _ = g 3;; (* missing `fun () ->' *)
1313 ^
1414-Error: This expression has type "int" but an expression was expected of type
1414+Error: The constant "3" has type "int" but an expression was expected of type
1515 "unit -> 'a"
1616 Hint: Did you forget to wrap the expression using "fun () ->"?
1717|}];;
···2828Line 3, characters 3-16:
29293 | print_newline; (* missing unit argument *)
3030 ^^^^^^^^^^^^^
3131-Error: This expression has type "unit -> unit"
3131+Error: The value "print_newline" has type "unit -> unit"
3232 but an expression was expected of type "unit"
3333 because it is in the left-hand side of a sequence
3434 Hint: Did you forget to provide "()" as argument?
···4141Line 2, characters 10-11:
42422 | print_int x;;
4343 ^
4444-Error: This expression has type "unit -> int"
4444+Error: The value "x" has type "unit -> int"
4545 but an expression was expected of type "int"
4646 Hint: Did you forget to provide "()" as argument?
4747|}];;
···5454Line 3, characters 6-7:
55553 | f = 3;;
5656 ^
5757-Error: This expression has type "int" but an expression was expected of type
5757+Error: The constant "3" has type "int" but an expression was expected of type
5858 "unit -> 'a"
5959 Hint: Did you forget to wrap the expression using "fun () ->"?
6060|}];;
···6767Line 3, characters 6-7:
68683 | 3 = f;;
6969 ^
7070-Error: This expression has type "unit -> 'a"
7171- but an expression was expected of type "int"
7070+Error: The value "f" has type "unit -> 'a" but an expression was expected of type
7171+ "int"
7272 Hint: Did you forget to provide "()" as argument?
7373|}]
+1-1
testsuite/tests/typing-extensions/extensions.ml
···231231Line 1, characters 10-11:
2322321 | let a = A 9
233233 ^
234234-Error: This expression has type "int" but an expression was expected of type
234234+Error: The constant "9" has type "int" but an expression was expected of type
235235 "[> `Var ]"
236236|}]
237237
···4646Line 3, characters 21-22:
47473 | Linear_map.scale s x
4848 ^
4949-Error: This expression has type "(module Scalar with type t = s)"
4949+Error: The value "s" has type "(module Scalar with type t = s)"
5050 but an expression was expected of type
5151 "(module Vector_space with type scalar = 'a and type t = 'b)"
5252|}];;
···117117Line 15, characters 8-10:
11811815 | unify ()
119119 ^^
120120-Error: This expression has type "unit" but an expression was expected of type
121121- "M.t"
120120+Error: The constructor "()" has type "unit"
121121+ but an expression was expected of type "M.t"
122122|}, Principal{|
123123module type S = sig type t val x : t end
124124Lines 8-12, characters 4-8:
···132132Line 15, characters 8-10:
13313315 | unify ()
134134 ^^
135135-Error: This expression has type "unit" but an expression was expected of type
136136- "M.t"
135135+Error: The constructor "()" has type "unit"
136136+ but an expression was expected of type "M.t"
137137|}];;
+6-10
testsuite/tests/typing-gadts/ambiguity.ml
···1818Line 3, characters 29-30:
19193 | | Refl -> if b then x else y
2020 ^
2121-Error: This expression has type "b" = "a" but an expression was expected of type
2222- "a"
2121+Error: The value "y" has type "b" = "a" but an expression was expected of type "a"
2322 This instance of "a" is ambiguous:
2423 it would escape the scope of its equation
2524|}]
···3332Line 3, characters 29-30:
34333 | | Refl -> if b then x else y
3534 ^
3636-Error: This expression has type "b" = "a" but an expression was expected of type
3737- "a"
3535+Error: The value "y" has type "b" = "a" but an expression was expected of type "a"
3836 This instance of "a" is ambiguous:
3937 it would escape the scope of its equation
4038|}]
···4846Line 3, characters 29-30:
49473 | | Refl -> if b then x else 0
5048 ^
5151-Error: This expression has type "int" but an expression was expected of type
4949+Error: The constant "0" has type "int" but an expression was expected of type
5250 "a" = "int"
5351 This instance of "int" is ambiguous:
5452 it would escape the scope of its equation
···6361Line 3, characters 29-30:
64623 | | Refl -> if b then x else 0
6563 ^
6666-Error: This expression has type "int" but an expression was expected of type
6464+Error: The constant "0" has type "int" but an expression was expected of type
6765 "a" = "int"
6866 This instance of "int" is ambiguous:
6967 it would escape the scope of its equation
···7977Line 3, characters 16-17:
80783 | | Refl -> [x; y]
8179 ^
8282-Error: This expression has type "b" = "a" but an expression was expected of type
8383- "a"
8080+Error: The value "y" has type "b" = "a" but an expression was expected of type "a"
8481 This instance of "a" is ambiguous:
8582 it would escape the scope of its equation
8683|}]
···9491Line 3, characters 16-17:
95923 | | Refl -> [x; y]
9693 ^
9797-Error: This expression has type "b" = "a" but an expression was expected of type
9898- "a"
9494+Error: The value "y" has type "b" = "a" but an expression was expected of type "a"
9995 This instance of "a" is ambiguous:
10096 it would escape the scope of its equation
10197|}]
+2-2
testsuite/tests/typing-gadts/didier.ml
···5454Line 4, characters 12-13:
55554 | | Bool -> x
5656 ^
5757-Error: This expression has type "t" = "bool"
5858- but an expression was expected of type "bool"
5757+Error: The value "x" has type "t" = "bool" but an expression was expected of type
5858+ "bool"
5959 This instance of "bool" is ambiguous:
6060 it would escape the scope of its equation
6161|}];;
+1-1
testsuite/tests/typing-gadts/or_patterns.ml
···632632Line 3, characters 13-14:
6336333 | | A | B -> 3 (* fails because the equation [a = int] doesn't escape any of
634634 ^
635635-Error: This expression has type "int" but an expression was expected of type "a"
635635+Error: The constant "3" has type "int" but an expression was expected of type "a"
636636|}]
637637638638(* Making sure we don't break a frequent pattern of GADTs indexed by polymorphic
···482482Line 4, characters 2-7:
4834834 | M.res;;
484484 ^^^^^
485485-Error: This expression has type "b" = "int"
485485+Error: The value "M.res" has type "b" = "int"
486486 but an expression was expected of type "'a"
487487 This instance of "int" is ambiguous:
488488 it would escape the scope of its equation
···497497Line 4, characters 3-8:
4984984 | M.res;;
499499 ^^^^^
500500-Error: This expression has type "int" but an expression was expected of type "'a"
500500+Error: The value "M.res" has type "int" but an expression was expected of type "'a"
501501 This instance of "int" is ambiguous:
502502 it would escape the scope of its equation
503503|}]
+1-1
testsuite/tests/typing-gadts/pr5689.ml
···103103Line 7, characters 35-43:
1041047 | | (Kind _, Ast_Text txt) -> Text txt
105105 ^^^^^^^^
106106-Error: This expression has type "[< inkind > `Nonlink ] inline_t"
106106+Error: This constructor has type "[< inkind > `Nonlink ] inline_t"
107107 but an expression was expected of type "a inline_t"
108108 Type "[< inkind > `Nonlink ]" = "[< `Link | `Nonlink > `Nonlink ]"
109109 is not compatible with type "a" = "[< `Link | `Nonlink ]"
+1-1
testsuite/tests/typing-gadts/pr5948.ml
···4242Line 25, characters 23-27:
434325 | | WrapPoly ATag -> intA
4444 ^^^^
4545-Error: This expression has type "[< `TagA of 'a ] -> 'a"
4545+Error: The value "intA" has type "[< `TagA of 'a ] -> 'a"
4646 but an expression was expected of type "a -> int"
4747 Type "[< `TagA of 'a ]" is not compatible with type
4848 "a" = "[< `TagA of int | `TagB ]"
+1-2
testsuite/tests/typing-gadts/pr6174.ml
···1010Line 3, characters 24-25:
11113 | fun C k -> k (fun x -> x);;
1212 ^
1313-Error: This expression has type "$0" but an expression was expected of type
1414- "$1" = "o"
1313+Error: The value "x" has type "$0" but an expression was expected of type "$1" = "o"
1514|}];;
+1-1
testsuite/tests/typing-gadts/pr6980.ml
···2424Line 11, characters 27-29:
252511 | let g (Aux(Second, f)) = f it;;
2626 ^^
2727-Error: This expression has type "[< `Bar | `Foo > `Bar ]"
2727+Error: The value "it" has type "[< `Bar | `Foo > `Bar ]"
2828 but an expression was expected of type "[< `Bar | `Foo ]"
2929 The second variant type is bound to "$a",
3030 it may not allow the tag(s) "`Bar"
+2-2
testsuite/tests/typing-gadts/pr7374.ml
···2424Line 7, characters 16-20:
25257 | fun Refl -> Refl
2626 ^^^^
2727-Error: This expression has type "(a, a) eq"
2727+Error: The constructor "Refl" has type "(a, a) eq"
2828 but an expression was expected of type "(a, t) eq"
2929 Type "a" is not compatible with type "t" = "[ `Rec of 'a ] X.t as 'a"
3030|}]
···5656Line 4, characters 21-25:
57574 | fun Refl Refl -> Refl;;
5858 ^^^^
5959-Error: This expression has type "(a, a) eq"
5959+Error: The constructor "Refl" has type "(a, a) eq"
6060 but an expression was expected of type "(a, a X.t X.t) eq"
6161 Type "a" = "b X.t" is not compatible with type "a X.t X.t"
6262 Type "b" is not compatible with type "a X.t"
···106106Line 3, characters 17-18:
1071073 | | IntLit, n -> n+1
108108 ^
109109-Error: This expression has type "a" but an expression was expected of type "int"
109109+Error: The value "n" has type "a" but an expression was expected of type "int"
110110|}]
111111112112(**********************)
+26-26
testsuite/tests/typing-gadts/test.ml
···293293Line 5, characters 21-22:
2942945 | let eval (D x) = x
295295 ^
296296-Error: This expression has type "$a t" but an expression was expected of type
297297- "'a"
296296+Error: The value "x" has type "$a t" but an expression was expected of type "'a"
298297 The type constructor "$a" would escape its scope
299298 Hint: "$a" is an existential type bound by the constructor "D".
300299|}];;
···377376Line 13, characters 19-20:
37837713 | | BoolLit b -> b
379378 ^
380380-Error: This expression has type "bool" but an expression was expected of type
379379+Error: The value "b" has type "bool" but an expression was expected of type
381380 "s" = "bool"
382381 This instance of "bool" is ambiguous:
383382 it would escape the scope of its equation
···586585Line 3, characters 44-45:
5875863 | match v with Int -> let y = either 1 x in y
588587 ^
589589-Error: This expression has type "int" but an expression was expected of type "'a"
588588+Error: The value "y" has type "int" but an expression was expected of type "'a"
590589 This instance of "int" is ambiguous:
591590 it would escape the scope of its equation
592591|}];;
···704703Line 2, characters 14-15:
7057042 | fun Eq o -> o
706705 ^
707707-Error: This expression has type "< m : a; .. >"
706706+Error: The value "o" has type "< m : a; .. >"
708707 but an expression was expected of type "< m : b; .. >"
709708 Type "a" is not compatible with type "b" = "a"
710709 This instance of "a" is ambiguous:
···717716Line 2, characters 22-23:
7187172 | match eq with Eq -> o ;; (* should fail *)
719718 ^
720720-Error: This expression has type "< m : a; .. >"
719719+Error: The value "o" has type "< m : a; .. >"
721720 but an expression was expected of type "< m : b; .. >"
722721 Type "a" is not compatible with type "b" = "a"
723722 This instance of "a" is ambiguous:
···757756Line 4, characters 44-45:
7587574 | let r : < m : b > = match eq with Eq -> o in (* fail with principal *)
759758 ^
760760-Error: This expression has type "< m : a >"
761761- but an expression was expected of type "< m : b >"
759759+Error: The value "o" has type "< m : a >" but an expression was expected of type
760760+ "< m : b >"
762761 Type "a" is not compatible with type "b" = "a"
763762 This instance of "a" is ambiguous:
764763 it would escape the scope of its equation
···773772Line 3, characters 44-45:
7747733 | let r : < m : b > = match eq with Eq -> o in (* fail *)
775774 ^
776776-Error: This expression has type "< m : a; .. >"
775775+Error: The value "o" has type "< m : a; .. >"
777776 but an expression was expected of type "< m : b >"
778777 Type "a" is not compatible with type "b" = "a"
779778 This instance of "a" is ambiguous:
···786785Line 2, characters 14-15:
7877862 | fun Eq o -> o ;; (* fail *)
788787 ^
789789-Error: This expression has type "[> `A of a ]"
788788+Error: The value "o" has type "[> `A of a ]"
790789 but an expression was expected of type "[> `A of b ]"
791790 Type "a" is not compatible with type "b" = "a"
792791 This instance of "a" is ambiguous:
···799798Line 2, characters 22-23:
8007992 | match eq with Eq -> v ;; (* should fail *)
801800 ^
802802-Error: This expression has type "[> `A of a ]"
801801+Error: The value "v" has type "[> `A of a ]"
803802 but an expression was expected of type "[> `A of b ]"
804803 Type "a" is not compatible with type "b" = "a"
805804 This instance of "a" is ambiguous:
···855854Line 4, characters 49-50:
8568554 | let r : [`A of b | `B] = match eq with Eq -> o in (* fail with principal *)
857856 ^
858858-Error: This expression has type "[ `A of a | `B ]"
857857+Error: The value "o" has type "[ `A of a | `B ]"
859858 but an expression was expected of type "[ `A of b | `B ]"
860859 Type "a" is not compatible with type "b" = "a"
861860 This instance of "a" is ambiguous:
···871870Line 3, characters 49-50:
8728713 | let r : [`A of b | `B] = match eq with Eq -> o in (* fail *)
873872 ^
874874-Error: This expression has type "[> `A of a | `B ]"
873873+Error: The value "o" has type "[> `A of a | `B ]"
875874 but an expression was expected of type "[ `A of b | `B ]"
876875 Type "a" is not compatible with type "b" = "a"
877876 This instance of "a" is ambiguous:
···10191018Line 6, characters 17-19:
102010196 | function Eq -> Eq (* fail *)
10211020 ^^
10221022-Error: This expression has type "(a, a) eq"
10211021+Error: The constructor "Eq" has type "(a, a) eq"
10231022 but an expression was expected of type "(a, b) eq"
10241023 Type "a" is not compatible with type "b"
10251024|}];;
···10751074Line 10, characters 3-4:
1076107510 | (x:<foo:int>)
10771076 ^
10781078-Error: This expression has type "t" = "< foo : int; .. >"
10771077+Error: The value "x" has type "t" = "< foo : int; .. >"
10791078 but an expression was expected of type "< foo : int >"
10801079 Type "$0" = "< bar : int; .. >" is not compatible with type "< >"
10811080 The second object type has no method "bar"
···10891088Line 3, characters 3-4:
109010893 | (x:<foo:int;bar:int>)
10911090 ^
10921092-Error: This expression has type "t" = "< foo : int; .. >"
10911091+Error: The value "x" has type "t" = "< foo : int; .. >"
10931092 but an expression was expected of type "< bar : int; foo : int >"
10941093 Type "$0" = "< bar : int; .. >" is not compatible with type "< bar : int >"
10951094 The first object type has an abstract row, it cannot be closed
···11341133Line 3, characters 5-10:
113511343 | x, x#foo, x#bar
11361135 ^^^^^
11371137-Error: This expression has type "int" but an expression was expected of type "'a"
11361136+Error: The method call "x#foo" has type "int"
11371137+ but an expression was expected of type "'a"
11381138 This instance of "int" is ambiguous:
11391139 it would escape the scope of its equation
11401140|}];;
···12021202Line 5, characters 24-25:
120312035 | if true then a else b
12041204 ^
12051205-Error: This expression has type "b" = "int"
12061206- but an expression was expected of type "a" = "int"
12051205+Error: The value "b" has type "b" = "int" but an expression was expected of type
12061206+ "a" = "int"
12071207 This instance of "int" is ambiguous:
12081208 it would escape the scope of its equation
12091209|}];;
···12191219Line 5, characters 24-25:
122012205 | if true then a else b
12211221 ^
12221222-Error: This expression has type "b" = "int"
12231223- but an expression was expected of type "a" = "int"
12221222+Error: The value "b" has type "b" = "int" but an expression was expected of type
12231223+ "a" = "int"
12241224 This instance of "int" is ambiguous:
12251225 it would escape the scope of its equation
12261226|}];;
···12341234Line 4, characters 19-20:
123512354 | if b then x else y
12361236 ^
12371237-Error: This expression has type "b" = "int"
12381238- but an expression was expected of type "a" = "int"
12371237+Error: The value "y" has type "b" = "int" but an expression was expected of type
12381238+ "a" = "int"
12391239 This instance of "int" is ambiguous:
12401240 it would escape the scope of its equation
12411241|}];;
···12481248Line 4, characters 19-20:
124912494 | if b then y else x
12501250 ^
12511251-Error: This expression has type "a" = "int"
12521252- but an expression was expected of type "b" = "int"
12511251+Error: The value "x" has type "a" = "int" but an expression was expected of type
12521252+ "b" = "int"
12531253 This instance of "int" is ambiguous:
12541254 it would escape the scope of its equation
12551255|}];;
···12871287Line 7, characters 35-36:
128812887 | if true then fun x -> x + 1 else x
12891289 ^
12901290-Error: This expression has type "M.t" = "int -> int"
12901290+Error: The value "x" has type "M.t" = "int -> int"
12911291 but an expression was expected of type "int -> int"
12921292 This instance of "int -> int" is ambiguous:
12931293 it would escape the scope of its equation
···11File "pr6303_bad.ml", line 11, characters 22-23:
2211 | let r' : string foo = r
33 ^
44-Error: This expression has type "int foo"
55- but an expression was expected of type "string foo"
44+Error: The value "r" has type "int foo" but an expression was expected of type
55+ "string foo"
66 Type "int" is not compatible with type "string"
+102
testsuite/tests/typing-misc/exp_denom.ml
···11+(* TEST
22+ expect;
33+*)
44+55+(* This test showcases the various denominations used in type clash errors *)
66+77+let f (x : < m : float >) = print_int x#m
88+99+[%%expect {|
1010+Line 1, characters 38-41:
1111+1 | let f (x : < m : float >) = print_int x#m
1212+ ^^^
1313+Error: The method call "x#m" has type "float"
1414+ but an expression was expected of type "int"
1515+|}]
1616+1717+type r = { f : float }
1818+1919+let f (x : r) = print_int x.f
2020+2121+[%%expect {|
2222+type r = { f : float; }
2323+Line 3, characters 26-29:
2424+3 | let f (x : r) = print_int x.f
2525+ ^^^
2626+Error: The field access "x.f" has type "float"
2727+ but an expression was expected of type "int"
2828+|}]
2929+3030+type v = Cons
3131+3232+let _ = print_int Cons
3333+3434+[%%expect {|
3535+type v = Cons
3636+Line 3, characters 18-22:
3737+3 | let _ = print_int Cons
3838+ ^^^^
3939+Error: The constructor "Cons" has type "v" but an expression was expected of type
4040+ "int"
4141+|}]
4242+4343+let _ = print_int `Cons
4444+4545+[%%expect {|
4646+Line 1, characters 18-23:
4747+1 | let _ = print_int `Cons
4848+ ^^^^^
4949+Error: The constructor "`Cons" has type "[> `Cons ]"
5050+ but an expression was expected of type "int"
5151+|}]
5252+5353+let v = 0.
5454+let _ = print_int v
5555+5656+[%%expect {|
5757+val v : float = 0.
5858+Line 2, characters 18-19:
5959+2 | let _ = print_int v
6060+ ^
6161+Error: The value "v" has type "float" but an expression was expected of type "int"
6262+|}]
6363+6464+let _ = print_int 0.
6565+6666+[%%expect {|
6767+Line 1, characters 18-20:
6868+1 | let _ = print_int 0.
6969+ ^^
7070+Error: The constant "0." has type "float" but an expression was expected of type
7171+ "int"
7272+|}]
7373+7474+let _ = print_int "foo"
7575+7676+[%%expect {|
7777+Line 1, characters 18-23:
7878+1 | let _ = print_int "foo"
7979+ ^^^^^
8080+Error: This constant has type "string" but an expression was expected of type
8181+ "int"
8282+|}]
8383+8484+let _ : int = while false do () done
8585+8686+[%%expect {|
8787+Line 1, characters 14-36:
8888+1 | let _ : int = while false do () done
8989+ ^^^^^^^^^^^^^^^^^^^^^^
9090+Error: This "while" expression has type "unit"
9191+ but an expression was expected of type "int"
9292+|}]
9393+9494+let _ : int = for _ = 1 to 2 do () done
9595+9696+[%%expect {|
9797+Line 1, characters 14-39:
9898+1 | let _ : int = for _ = 1 to 2 do () done
9999+ ^^^^^^^^^^^^^^^^^^^^^^^^^
100100+Error: This "for" expression has type "unit"
101101+ but an expression was expected of type "int"
102102+|}]
+3-3
testsuite/tests/typing-misc/labels.ml
···170170Line 1, characters 26-33:
1711711 | let () = expect_unlabeled labeled
172172 ^^^^^^^
173173-Error: This expression has type "x:'a -> unit"
173173+Error: The value "labeled" has type "x:'a -> unit"
174174 but an expression was expected of type "unit -> unit"
175175 The first argument is labeled "x",
176176 but an unlabeled argument was expected
···181181Line 1, characters 24-33:
1821821 | let () = expect_labeled unlabeled
183183 ^^^^^^^^^
184184-Error: This expression has type "'a -> unit"
184184+Error: The value "unlabeled" has type "'a -> unit"
185185 but an expression was expected of type "x:'b -> unit"
186186 A label "x" was expected
187187|}]
···191191Line 1, characters 24-35:
1921921 | let () = expect_labeled wrong_label
193193 ^^^^^^^^^^^
194194-Error: This expression has type "y:'a -> unit"
194194+Error: The value "wrong_label" has type "y:'a -> unit"
195195 but an expression was expected of type "x:'b -> unit"
196196 Labels "y" and "x" do not match
197197|}]
+1-1
testsuite/tests/typing-misc/let_rec_approx.ml
···1717Line 1, characters 17-19:
18181 | let rec f () = g 42
1919 ^^
2020-Error: This expression has type "int" but an expression was expected of type
2020+Error: The constant "42" has type "int" but an expression was expected of type
2121 "string"
2222|}]
2323
+4-4
testsuite/tests/typing-misc/occur_check.ml
···1111Line 2, characters 42-43:
12122 | let f (g : 'a list -> 'a t -> 'a) s = g s s;;
1313 ^
1414-Error: This expression has type "'a list"
1515- but an expression was expected of type "'a t" = "'a"
1414+Error: The value "s" has type "'a list" but an expression was expected of type
1515+ "'a t" = "'a"
1616 The type variable "'a" occurs inside "'a list"
1717|}];;
1818···2121Line 1, characters 42-43:
22221 | let f (g : 'a * 'b -> 'a t -> 'a) s = g s s;;
2323 ^
2424-Error: This expression has type "'a * 'b"
2525- but an expression was expected of type "'a t" = "'a"
2424+Error: The value "s" has type "'a * 'b" but an expression was expected of type
2525+ "'a t" = "'a"
2626 The type variable "'a" occurs inside "'a * 'b"
2727|}];;
2828
+5-6
testsuite/tests/typing-misc/polyvars.ml
···180180Line 2, characters 30-31:
1811812 | let f: t -> [ `A ] = fun x -> x
182182 ^
183183-Error: This expression has type "t" but an expression was expected of type
184184- "[ `A ]"
183183+Error: The value "x" has type "t" but an expression was expected of type "[ `A ]"
185184 The first variant type is private, it may not allow the tag(s) "`A"
186185|}]
187186···242241Line 5, characters 25-26:
2432425 | let f (x:[`X of int]) = (x:[`X])
244243 ^
245245-Error: This expression has type "[ `X of int ]"
244244+Error: The value "x" has type "[ `X of int ]"
246245 but an expression was expected of type "[ `X ]"
247246 Types for tag "`X" are incompatible
248247|}]
···253252Line 1, characters 25-26:
2542531 | let f (x:[`X of int]) = (x:[<`X of & int])
255254 ^
256256-Error: This expression has type "[ `X of int ]"
255255+Error: The value "x" has type "[ `X of int ]"
257256 but an expression was expected of type "[< `X of & int ]"
258257 Types for tag "`X" are incompatible
259258|}]
···265264Line 3, characters 36-37:
2662653 | let f (x:[<`X of & int & float]) = (x:[`X])
267266 ^
268268-Error: This expression has type "[< `X of & int & float ]"
267267+Error: The value "x" has type "[< `X of & int & float ]"
269268 but an expression was expected of type "[ `X ]"
270269 Types for tag "`X" are incompatible
271270|}]
···282281Line 4, characters 30-31:
2832824 | let g (x:[`A | `R of rt]) = f x
284283 ^
285285-Error: This expression has type "[ `A | `R of rt ]"
284284+Error: The value "x" has type "[ `A | `R of rt ]"
286285 but an expression was expected of type "[< `A | `R of 'a ] as 'a"
287286 Type "rt" = "[ `A | `B of string | `R of rt ]" is not compatible with type
288287 "[< `A | `R of 'a ] as 'a"
+3-3
testsuite/tests/typing-misc/pr7103.ml
···2323Line 1, characters 27-28:
24241 | let _ = fun (x : a t) -> f x;;
2525 ^
2626-Error: This expression has type "a t" but an expression was expected of type
2626+Error: The value "x" has type "a t" but an expression was expected of type
2727 "< .. > t"
2828 Type "a" is not compatible with type "< .. >"
2929|}];;
···3333Line 1, characters 27-28:
34341 | let _ = fun (x : a t) -> g x;;
3535 ^
3636-Error: This expression has type "a t" but an expression was expected of type
3636+Error: The value "x" has type "a t" but an expression was expected of type
3737 "[< `b ] t"
3838 Type "a" is not compatible with type "[< `b ]"
3939|}];;
···4343Line 1, characters 27-28:
44441 | let _ = fun (x : a t) -> h x;;
4545 ^
4646-Error: This expression has type "a t" but an expression was expected of type
4646+Error: The value "x" has type "a t" but an expression was expected of type
4747 "[> `b ] t"
4848 Type "a" is not compatible with type "[> `b ]"
4949|}];;
+2-2
testsuite/tests/typing-misc/pr7937.ml
···1010Line 3, characters 35-39:
11113 | let f: 'a. 'a r -> 'a r = fun x -> true;;
1212 ^^^^
1313-Error: This expression has type "bool" but an expression was expected of type
1414- "([< `X of int & 'a ] as 'a) r"
1313+Error: The constructor "\#true" has type "bool"
1414+ but an expression was expected of type "([< `X of int & 'a ] as 'a) r"
1515|}]
16161717let g: 'a. 'a r -> 'a r = fun x -> { contents = 0 };;
+2-2
testsuite/tests/typing-misc/printing.ml
···7979Line 4, characters 32-33:
80804 | | Refl -> if true then x else y
8181 ^
8282-Error: This expression has type "a" but an expression was expected of type "t"
8282+Error: The value "y" has type "a" but an expression was expected of type "t"
8383 This instance of "< m : int * 'a > as 'a" is ambiguous:
8484 it would escape the scope of its equation
8585|}]
···9494Line 3, characters 22-23:
95953 | let f (x : t1) : t2 = x;;
9696 ^
9797-Error: This expression has type "t1" but an expression was expected of type "t2"
9797+Error: The value "x" has type "t1" but an expression was expected of type "t2"
9898 The method "m" has type "'c. 'c * ('a * < m : 'c. 'b >) as 'b",
9999 but the expected method type was "'a. 'a * ('a * < m : 'a. 'd >) as 'd"
100100 The universal variable "'a" would escape its scope
+1-1
testsuite/tests/typing-misc/scope_escape.ml
···99Line 2, characters 34-35:
10102 | module M = struct type t let _ = (x : t list ref) end;;
1111 ^
1212-Error: This expression has type "'weak1 list ref"
1212+Error: The value "x" has type "'weak1 list ref"
1313 but an expression was expected of type "t list ref"
1414 The type constructor "t" would escape its scope
1515|}]
···1414Line 5, characters 27-28:
15155 | let f: t -> t = fun B -> x
1616 ^
1717-Error: This expression has type "t/2" but an expression was expected of type "t"
1717+Error: The value "x" has type "t/2" but an expression was expected of type "t"
1818 Line 4, characters 2-12:
1919 Definition of type "t"
2020 Line 1, characters 0-10:
···3636Line 7, characters 34-35:
37377 | let f : M.t -> M.t = fun M.C -> y
3838 ^
3939-Error: This expression has type "M/2.t" but an expression was expected of type
4040- "M.t"
3939+Error: The value "y" has type "M/2.t" but an expression was expected of type "M.t"
4140 Lines 4-6, characters 2-5:
4241 Definition of module "M"
4342 Line 1, characters 0-32:
···5352Line 2, characters 25-26:
54532 | let f: t -> t = fun D -> x;;
5554 ^
5656-Error: This expression has type "t/2" but an expression was expected of type "t"
5555+Error: The value "x" has type "t/2" but an expression was expected of type "t"
5756 Line 1, characters 0-10:
5857 Definition of type "t"
5958 Line 1, characters 0-10:
···7675Line 2, characters 32-33:
77762 | let x: ttt = let rec y = A y in y;;
7877 ^
7979-Error: This expression has type "ttt/2" but an expression was expected of type
8080- "ttt"
7878+Error: The value "y" has type "ttt/2" but an expression was expected of type "ttt"
8179 Line 1, characters 0-26:
8280 Definition of type "ttt"
8381 Line 2, characters 0-30:
+1-1
testsuite/tests/typing-missing-cmi-3/user.ml
···3232Line 1, characters 19-20:
33331 | let () = Middle.(f x)
3434 ^
3535-Error: This expression has type "(module Original.T)"
3535+Error: The value "x" has type "(module Original.T)"
3636 but an expression was expected of type
3737 "(module Original.T with type t = int)"
3838|}]
···11File "main.ml", line 1, characters 14-17:
221 | let _ = A.a = B.b
33 ^^^
44-Error: This expression has type "M.b" but an expression was expected of type
55- "M.a"
44+Error: The value "B.b" has type "M.b" but an expression was expected of type "M.a"
65 Type "M.b" is abstract because no corresponding cmi file was found
76 in path.
87 Type "M.a" is abstract because no corresponding cmi file was found
···11File "pr6752_bad.ml", line 26, characters 31-40:
2226 | let q' : Common0.msg Queue.t = Common0.q
33 ^^^^^^^^^
44-Error: This expression has type "'a Queue.t"
44+Error: The value "Common0.q" has type "'a Queue.t"
55 but an expression was expected of type "Common0.msg Queue.t"
66 The type constructor "Common0.msg" would escape its scope
···11File "pr6992_bad.ml", line 16, characters 69-71:
2216 | let uniq (type a) (type b) (Eq : a fix) (Eq : b fix) : (a, b) eq = Eq
33 ^^
44-Error: This expression has type "(a, a) eq"
44+Error: The constructor "Eq" has type "(a, a) eq"
55 but an expression was expected of type "(a, b) eq"
66 Type "a" is not compatible with type "b"
+1-2
testsuite/tests/typing-modules/firstclass.ml
···3232Line 5, characters 3-4:
33335 | (x : (module S'));; (* fail *)
3434 ^
3535-Error: This expression has type
3636- "(module S2 with type t = int and type u = bool)"
3535+Error: The value "x" has type "(module S2 with type t = int and type u = bool)"
3736 but an expression was expected of type "(module S')"
3837 Modules do not match:
3938 S'
+2-2
testsuite/tests/typing-objects/Exemples.ml
···207207Line 1, characters 27-28:
2082081 | let c'' = new color_circle p;;
209209 ^
210210-Error: This expression has type "point" but an expression was expected of type
210210+Error: The value "p" has type "point" but an expression was expected of type
211211 "#color_point"
212212 The first object type has no method "color"
213213|}];;
···588588Line 1, characters 25-27:
5895891 | (new sorted_list ())#add c3;;
590590 ^^
591591-Error: This expression has type
591591+Error: The value "c3" has type
592592 "int_comparable3" =
593593 "< cmp : int_comparable -> int; setx : int -> unit; x : int >"
594594 but an expression was expected of type
+5-6
testsuite/tests/typing-objects/Tests.ml
···416416Line 1, characters 30-34:
4174171 | class c () = object val x = - true val y = -. () end;;
418418 ^^^^
419419-Error: This expression has type "bool" but an expression was expected of type
420420- "int"
419419+Error: The constructor "\#true" has type "bool"
420420+ but an expression was expected of type "int"
421421|}];;
422422423423class c () = object method f = 1 method g = 1 method h = 1 end;;
···789789Line 1, characters 19-20:
7907901 | fun (x : 'a t) -> (x : 'a); ();;
791791 ^
792792-Error: This expression has type "'a t" but an expression was expected of type
793793- "'a"
792792+Error: The value "x" has type "'a t" but an expression was expected of type "'a"
794793 The type variable "'a" occurs inside "'a t"
795794|}];;
796795fun ((x : 'a) | (x : 'a t)) -> ();;
···11431142Line 2, characters 54-58:
114411432 | class c = object (self) method private foo = is_empty self end;;
11451144 ^^^^
11461146-Error: This expression has type "< .. >" but an expression was expected of type
11451145+Error: The value "self" has type "< .. >" but an expression was expected of type
11471146 "< >"
11481147 Self type cannot be unified with a closed object type
11491148|}];;
···12371236Line 1, characters 41-45:
123812371 | let o = object(self) initializer has_foo self end;;
12391238 ^^^^
12401240-Error: This expression has type "< >" but an expression was expected of type
12391239+Error: The value "self" has type "< >" but an expression was expected of type
12411240 "< foo : int; .. >"
12421241 The first object type has no method "foo"
12431242|}];;
+2-2
testsuite/tests/typing-objects/abstract_rows.ml
···1111Line 4, characters 24-25:
12124 | let f (x:t) (y:u) = x = y;;
1313 ^
1414-Error: This expression has type "u" but an expression was expected of type "t"
1414+Error: The value "y" has type "u" but an expression was expected of type "t"
1515 The second object type has an abstract row, it cannot be closed
1616|}]
1717···2121Line 1, characters 24-25:
22221 | let g (x:u) (y:t) = x = y;;
2323 ^
2424-Error: This expression has type "t" but an expression was expected of type "u"
2424+Error: The value "y" has type "t" but an expression was expected of type "u"
2525 The first object type has an abstract row, it cannot be closed
2626|}]
+6-6
testsuite/tests/typing-objects/dummy.ml
···4545Line 16, characters 22-26:
464616 | inherit child1' self
4747 ^^^^
4848-Error: This expression has type "< child : 'a; previous : 'b option; .. >"
4848+Error: The value "self" has type "< child : 'a; previous : 'b option; .. >"
4949 but an expression was expected of type "'c"
5050 Self type cannot escape its class
5151|}]
···193193Line 3, characters 36-41:
1941943 | inherit parameter_contains_self param
195195 ^^^^^
196196-Error: This expression has type
196196+Error: The value "param" has type
197197 "< redrawWidget : parameter_contains_self -> unit; .. >"
198198 but an expression was expected of type
199199 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >"
···209209Line 3, characters 26-31:
2102103 | parameter_contains_self param;;
211211 ^^^^^
212212-Error: This expression has type
212212+Error: The value "param" has type
213213 "< redrawWidget : parameter_contains_self -> unit; .. >"
214214 but an expression was expected of type
215215 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >"
···229229Line 4, characters 38-43:
2302304 | inherit parameter_contains_self param
231231 ^^^^^
232232-Error: This expression has type "'a" but an expression was expected of type
232232+Error: The value "param" has type "'a" but an expression was expected of type
233233 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >"
234234 Self type cannot escape its class
235235|}]
···243243Line 3, characters 38-43:
2442443 | class c = parameter_contains_self param
245245 ^^^^^
246246-Error: This expression has type "'a" but an expression was expected of type
246246+Error: The value "param" has type "'a" but an expression was expected of type
247247 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >"
248248 Self type cannot escape its class
249249|}]
···256256Line 3, characters 36-41:
2572573 | inherit parameter_contains_self param
258258 ^^^^^
259259-Error: This expression has type
259259+Error: The value "param" has type
260260 "< redrawWidget : parameter_contains_self -> unit; .. >"
261261 but an expression was expected of type
262262 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >"
+1-1
testsuite/tests/typing-objects/pr6123_bad.ml
···2929Line 15, characters 50-54:
303015 | let args = List.map (fun ty -> new argument(self, ty)) args_ty in
3131 ^^^^
3232-Error: This expression has type "< arguments : 'a; .. >"
3232+Error: The value "self" has type "< arguments : 'a; .. >"
3333 but an expression was expected of type "'b"
3434 Self type cannot escape its class
3535|}]
···1111Line 1, characters 54-58:
12121 | class c = object (self) method private foo = is_empty self end;;
1313 ^^^^
1414-Error: This expression has type "< .. >" but an expression was expected of type
1414+Error: The value "self" has type "< .. >" but an expression was expected of type
1515 "< >"
1616 Self type cannot be unified with a closed object type
1717|}]
+6-6
testsuite/tests/typing-poly/error_messages.ml
···3636Line 4, characters 49-50:
37374 | let f (x:<a:'a; b:'a. 'a>) (y:<a:'a;b:'a>) = x = y
3838 ^
3939-Error: This expression has type "< a : 'a; b : 'a >"
3939+Error: The value "y" has type "< a : 'a; b : 'a >"
4040 but an expression was expected of type "< a : 'a; b : 'a0. 'a0 >"
4141 The method "b" has type "'a", but the expected method type was "'a0. 'a0"
4242 The universal variable "'a0" would escape its scope
···9191Line 1, characters 48-49:
92921 | let f: 'a. ([> `A ] as 'a) -> [ `A ] = fun x -> x
9393 ^
9494-Error: This expression has type "[> `A ]"
9595- but an expression was expected of type "[ `A ]"
9494+Error: The value "x" has type "[> `A ]" but an expression was expected of type
9595+ "[ `A ]"
9696 The first variant type is bound to the universal type variable "'a",
9797 it cannot be closed
9898|}]
···102102Line 1, characters 48-49:
1031031 | let f: 'a. [ `A ] -> ([> `A ] as 'a) = fun x -> x
104104 ^
105105-Error: This expression has type "[ `A ]" but an expression was expected of type
105105+Error: The value "x" has type "[ `A ]" but an expression was expected of type
106106 "[> `A ]"
107107 The second variant type is bound to the universal type variable "'a",
108108 it cannot be closed
···114114Line 1, characters 53-54:
1151151 | let f: 'a. [ `A | `B ] -> ([> `A ] as 'a) = fun x -> x
116116 ^
117117-Error: This expression has type "[ `A | `B ]"
117117+Error: The value "x" has type "[ `A | `B ]"
118118 but an expression was expected of type "[> `A ]"
119119 The second variant type is bound to the universal type variable "'a",
120120 it cannot be closed
···126126Line 1, characters 59-60:
1271271 | let f: 'a. [> `A | `B | `C ] -> ([> `A ] as 'a) = fun x -> x
128128 ^
129129-Error: This expression has type "[> `A | `B | `C ]"
129129+Error: The value "x" has type "[> `A | `B | `C ]"
130130 but an expression was expected of type "[> `A ]"
131131 The second variant type is bound to the universal type variable "'a",
132132 it may not allow the tag(s) "`B", "`C"
+10-11
testsuite/tests/typing-poly/poly.ml
···466466Line 9, characters 41-42:
4674679 | let f (x : < m : 'a. 'a -> 'a list >) = (x : < m : 'b. 'b -> 'c >)
468468 ^
469469-Error: This expression has type "< m : 'b. 'b -> 'b list >"
469469+Error: The value "x" has type "< m : 'b. 'b -> 'b list >"
470470 but an expression was expected of type "< m : 'b. 'b -> 'c >"
471471 The method "m" has type "'b. 'b -> 'b list",
472472 but the expected method type was "'b. 'b -> 'c"
···590590Line 5, characters 24-28:
5915915 | let f3 f = f#id 1, f#id true
592592 ^^^^
593593-Error: This expression has type "bool" but an expression was expected of type
594594- "int"
593593+Error: The constructor "\#true" has type "bool"
594594+ but an expression was expected of type "int"
595595|}];;
596596597597class c = object
···11341134Line 2, characters 3-4:
113511352 | (x : <m : 'a. 'a * (<m:'b. 'a * <m:'c. 'c * 'bar> > as 'bar) >);;
11361136 ^
11371137-Error: This expression has type "< m : 'a. 'a * < m : 'a * 'b > > as 'b"
11371137+Error: The value "x" has type "< m : 'a. 'a * < m : 'a * 'b > > as 'b"
11381138 but an expression was expected of type
11391139 "< m : 'a. 'a * (< m : 'a * < m : 'c. 'c * 'd > > as 'd) >"
11401140 The method "m" has type
···11571157Line 2, characters 3-4:
115811582 | (x : <m : 'b. 'b * ('b * <m : 'c. 'c * ('c * 'bar)>)> as 'bar);;
11591159 ^
11601160-Error: This expression has type
11611161- "< m : 'b. 'b * ('b * < m : 'c. 'c * 'a > as 'a) >"
11601160+Error: The value "x" has type "< m : 'b. 'b * ('b * < m : 'c. 'c * 'a > as 'a) >"
11621161 but an expression was expected of type
11631162 "< m : 'b. 'b * ('b * < m : 'c. 'c * ('c * 'd) >) > as 'd"
11641163 The method "m" has type "'c. 'c * ('b * < m : 'c. 'e >) as 'e",
···13991398Line 4, characters 16-22:
140013994 | let zero = {f = `Int 0} ;; (* fails *)
14011400 ^^^^^^
14021402-Error: This expression has type "[> `Int of int ]"
14011401+Error: This constructor has type "[> `Int of int ]"
14031402 but an expression was expected of type "[< `Int of int ]"
14041403 The second variant type is bound to the universal type variable "'a",
14051404 it may not allow the tag(s) "`Int"
···15721571Line 2, characters 3-4:
157315722 | (n : < m : 'b 'r. [< `Foo of int & 'b | `Bar] as 'r >)
15741573 ^
15751575-Error: This expression has type
15761576- "< m : 'a 'c. [< `Bar | `Foo of 'a & int ] as 'c >"
15741574+Error: The value "n" has type "< m : 'a 'c. [< `Bar | `Foo of 'a & int ] as 'c >"
15771575 but an expression was expected of type
15781576 "< m : 'b 'd. [< `Bar | `Foo of int & 'b ] as 'd >"
15791577 Types for tag "`Foo" are incompatible
···15951593Line 3, characters 19-22:
159615943 | if b then x else M.A;;
15971595 ^^^
15981598-Error: This expression has type "M.t" but an expression was expected of type "'x"
15961596+Error: The constructor "M.A" has type "M.t"
15971597+ but an expression was expected of type "'x"
15991598 The type constructor "M.t" would escape its scope
16001599|}];;
16011600···18911890Line 1, characters 17-18:
189218911 | let f (x : u) = (x : v)
18931892 ^
18941894-Error: This expression has type "u" but an expression was expected of type "v"
18931893+Error: The value "x" has type "u" but an expression was expected of type "v"
18951894 The method "m" has type "'a s list * < m : 'b > as 'b",
18961895 but the expected method type was "'a. 'a s list * < m : 'a. 'c > as 'c"
18971896 The universal variable "'a" would escape its scope
+1-1
testsuite/tests/typing-poly/pr9603.ml
···2525Line 4, characters 11-12:
26264 | = fun x -> x
2727 ^
2828-Error: This expression has type
2828+Error: The value "x" has type
2929 "< m : 'left 'right. < left : 'left; right : 'right > pair >"
3030 but an expression was expected of type
3131 "< m : 'left 'right. < left : 'left; right : 'right > pair >"
···11File "pr3918c.ml", line 24, characters 11-12:
2224 | let f x = (x : 'a vlist :> 'b vlist)
33 ^
44-Error: This expression has type "'b Pr3918b.vlist"
44+Error: The value "x" has type "'b Pr3918b.vlist"
55 but an expression was expected of type "'b Pr3918b.vlist"
···11File "pr5057a_bad.ml", line 14, characters 48-49:
2214 | let _ = match flag with `A -> T.mem | `B r -> r in
33 ^
44-Error: This expression has type "'a" but an expression was expected of type
44+Error: The value "r" has type "'a" but an expression was expected of type
55 "int -> T.t -> bool"
66 The type constructor "T.t" would escape its scope
···33Line 2, characters 20-21:
442 | let f (x : F0.t) = (x : Foobar.t);; (* fails *)
55 ^
66-Error: This expression has type "F0.t" but an expression was expected of type
66+Error: The value "x" has type "F0.t" but an expression was expected of type
77 "Foobar.t"
88module F = Foobar
99val f : F.t -> Foobar.t = <fun>
···1313Line 1, characters 19-20:
14141 | fun (x : M1.t) -> (x : M2.t);; (* fails *)
1515 ^
1616-Error: This expression has type "M1.t" but an expression was expected of type
1717- "M2.t"
1616+Error: The value "x" has type "M1.t" but an expression was expected of type "M2.t"
1817module M3 : sig type t = private M1.t end
1918- : M3.t -> M1.t = <fun>
2019- : M3.t -> M.t = <fun>
···33Line 2, characters 20-21:
442 | let f (x : F0.t) = (x : Foobar.t);; (* fails *)
55 ^
66-Error: This expression has type "F0.t" but an expression was expected of type
66+Error: The value "x" has type "F0.t" but an expression was expected of type
77 "Foobar.t"
88module F = Foobar
99val f : F.t -> Foobar.t = <fun>
···1313Line 1, characters 19-20:
14141 | fun (x : M1.t) -> (x : M2.t);; (* fails *)
1515 ^
1616-Error: This expression has type "M1.t" but an expression was expected of type
1717- "M2.t"
1616+Error: The value "x" has type "M1.t" but an expression was expected of type "M2.t"
1817module M3 : sig type t = private M1.t end
1918- : M3.t -> M1.t = <fun>
2019- : M3.t -> M.t = <fun>
···11File "pr6174_bad.ml", line 11, characters 24-25:
2211 | fun C k -> k (fun x -> x);;
33 ^
44-Error: This expression has type "$0" but an expression was expected of type
44+Error: The value "x" has type "$0" but an expression was expected of type
55 "$1" = "($2 -> $1) -> $1"
+2-2
testsuite/tests/typing-short-paths/errors.ml
···5151Line 9, characters 22-23:
52529 | | Pair (Char, x) -> x + 1
5353 ^
5454-Error: This expression has type "$a" but an expression was expected of type "int"
5454+Error: The value "x" has type "$a" but an expression was expected of type "int"
5555 Hint: "$a" is an existential type bound by the constructor "Pair".
5656|}]
5757···6868Line 7, characters 35-36:
69697 | | Pair (Char, x) -> if true then x else 'd'
7070 ^
7171-Error: This expression has type "$a" but an expression was expected of type "'a"
7171+Error: The value "x" has type "$a" but an expression was expected of type "'a"
7272 This instance of "$a" is ambiguous:
7373 it would escape the scope of its equation
7474 Hint: "$a" is an existential type bound by the constructor "Pair".
···6969Line 1, characters 8-9:
70701 | let y = x + x ;;
7171 ^
7272-Error: This expression has type "'a Int.Map.t"
7272+Error: The value "x" has type "'a Int.Map.t"
7373 but an expression was expected of type "int"
7474module M : sig type t = A type u = C end
7575module N : sig type t = B end
···88Line 2, characters 32-33:
992 | let f x (type a) (y : a) = (x = y);; (* Fails *)
1010 ^
1111-Error: This expression has type "a" but an expression was expected of type "'a"
1111+Error: The value "y" has type "a" but an expression was expected of type "'a"
1212 The type constructor "a" would escape its scope
1313Line 3, characters 53-54:
14143 | method n : 'a -> 'a = fun (type g) (x:g) -> self#m x
1515 ^
1616-Error: This expression has type "g" but an expression was expected of type "'a"
1616+Error: The value "x" has type "g" but an expression was expected of type "'a"
1717 The type constructor "g" would escape its scope
1818
+1-2
testsuite/tests/typing-warnings/records.ml
···106106Line 3, characters 35-36:
1071073 | let f r = match r with {x; y} -> y + y
108108 ^
109109-Error: This expression has type "bool" but an expression was expected of type
110110- "int"
109109+Error: The value "y" has type "bool" but an expression was expected of type "int"
111110|}]
112111113112module F2 = struct
+80-43
typing/typecore.ml
···111111 | Orpat_vars of Ident.t * Ident.t list
112112 | Expr_type_clash of
113113 Errortrace.unification_error * type_forcing_context option
114114- * Parsetree.expression_desc option
114114+ * Parsetree.expression option
115115 | Function_arity_type_clash of
116116 { syntactic_arity : int;
117117 type_constraint : type_expr;
···3161316131623162(* Typing of expressions *)
3163316331643164-(** [sdesc_for_hint] is used by error messages to report literals in their
31643164+(** [sexp_for_hint] is used by error messages to report literals in their
31653165 original formatting *)
31663166-let unify_exp ?sdesc_for_hint env exp expected_ty =
31663166+let unify_exp ~sexp env exp expected_ty =
31673167 let loc = proper_exp_loc exp in
31683168 try
31693169 unify_exp_types loc env exp.exp_type expected_ty
31703170 with Error(loc, env, Expr_type_clash(err, tfc, None)) ->
31713171- raise (Error(loc, env, Expr_type_clash(err, tfc, sdesc_for_hint)))
31713171+ raise (Error(loc, env, Expr_type_clash(err, tfc, Some sexp)))
3172317231733173(* If [is_inferred e] is true, [e] will be typechecked without using
31743174 the "expected type" provided by the context. *)
···33133313 env sexp ty_expected_explained =
33143314 let { ty = ty_expected; explanation } = ty_expected_explained in
33153315 let loc = sexp.pexp_loc in
33163316- let desc = sexp.pexp_desc in
33173316 (* Record the expression type before unifying it with the expected type *)
33183317 let with_explanation = with_explanation explanation in
33193318 (* Unify the result with [ty_expected], enforcing the current level *)
33203319 let rue exp =
33213320 with_explanation (fun () ->
33223322- unify_exp ~sdesc_for_hint:desc env (re exp) (instance ty_expected));
33213321+ unify_exp ~sexp env (re exp) (instance ty_expected));
33233322 exp
33243323 in
33253325- match desc with
33243324+ match sexp.pexp_desc with
33263325 | Pexp_ident lid ->
33273326 let path, desc = type_ident env ~recarg lid in
33283327 let exp_desc =
···34553454 end
34563455 ~before_generalize:(fun (_pat_exp_list, body, new_env) ->
34573456 (* The "body" component of the scope escape check. *)
34583458- unify_exp new_env body (newvar ()))
34573457+ unify_exp ~sexp new_env body (newvar ()))
34593458 in
34603459 re {
34613460 exp_desc = Texp_let(rec_flag, pat_exp_list, body);
···36533652 exp_attributes = sexp.pexp_attributes;
36543653 exp_env = env }
36553654 | Pexp_construct(lid, sarg) ->
36563656- type_construct env loc lid sarg ty_expected_explained sexp.pexp_attributes
36553655+ type_construct env ~sexp lid sarg ty_expected_explained
36573656 | Pexp_variant(l, sarg) ->
36583657 (* Keep sharing *)
36593658 let ty_expected1 = protect_expansion env ty_expected in
···38423841 type_label_access env srecord Env.Projection lid
38433842 in
38443843 let (_, ty_arg, ty_res) = instance_label ~fixed:false label in
38453845- unify_exp env record ty_res;
38443844+ unify_exp ~sexp env record ty_res;
38463845 rue {
38473846 exp_desc = Texp_field(record, lid, label);
38483847 exp_loc = loc; exp_extra = [];
···38563855 if expected_type = None then newvar () else record.exp_type in
38573856 let (label_loc, label, newval) =
38583857 type_label_exp false env loc ty_record (lid, label, snewval) in
38593859- unify_exp env record ty_record;
38583858+ unify_exp ~sexp env record ty_record;
38603859 if label.lbl_mut = Immutable then
38613860 raise(Error(loc, env, Label_not_mutable lid.txt));
38623861 rue {
···38953894 let ifso = type_expect env sifso ty_expected_explained in
38963895 let ifnot = type_expect env sifnot ty_expected_explained in
38973896 (* Keep sharing *)
38983898- unify_exp env ifnot ifso.exp_type;
38973897+ unify_exp ~sexp env ifnot ifso.exp_type;
38993898 re {
39003899 exp_desc = Texp_ifthenelse(cond, ifso, Some ifnot);
39013900 exp_loc = loc; exp_extra = [];
···42284227 | Tvar _ ->
42294228 let exp = type_exp env sbody in
42304229 let exp = {exp with exp_type = newty (Tpoly (exp.exp_type, []))} in
42314231- unify_exp env exp ty;
42304230+ unify_exp ~sexp env exp ty;
42324231 exp
42334232 | _ -> assert false
42344233 in
···52075206 let args, ty_fun', simple_res = make_args [] texp.exp_type
52085207 and texp = {texp with exp_type = instance texp.exp_type} in
52095208 if not (simple_res || safe_expect) then begin
52105210- unify_exp env texp ty_expected;
52095209+ unify_exp ~sexp:sarg env texp ty_expected;
52115210 texp
52125211 end else begin
52135212 let warn = !Clflags.principal &&
···52185217 Tarrow(Nolabel,ty_arg,ty_res,_) -> ty_arg, ty_res
52195218 | _ -> assert false
52205219 in
52215221- unify_exp env {texp with exp_type = ty_fun} ty_expected;
52205220+ unify_exp ~sexp:sarg env {texp with exp_type = ty_fun} ty_expected;
52225221 if args = [] then texp else
52235222 (* eta-expand to avoid side effects *)
52245223 let var_pair name ty =
···52785277 | None ->
52795278 let texp = type_expect ?recarg env sarg
52805279 (mk_expected ?explanation ty_expected') in
52815281- unify_exp env texp ty_expected;
52805280+ unify_exp ~sexp:sarg env texp ty_expected;
52825281 texp
5283528252845283and type_application env funct sargs =
···53435342 let arg () =
53445343 let arg = type_expect env sarg (mk_expected ty_arg) in
53455344 if is_optional lbl then
53465346- unify_exp env arg (type_option(newvar()));
53455345+ unify_exp ~sexp:sarg env arg (type_option(newvar()));
53475346 arg
53485347 in
53495348 (ty_res, (lbl, Some (arg, Some sarg.pexp_loc)) :: typed_args)
···54865485 let ty = funct.exp_type in
54875486 type_args [] ty (instance ty) sargs
5488548754895489-and type_construct env loc lid sarg ty_expected_explained attrs =
54885488+and type_construct env ~sexp lid sarg ty_expected_explained =
54905489 let { ty = ty_expected; explanation } = ty_expected_explained in
54915490 let expected_type =
54925491 match extract_concrete_variant env ty_expected with
···54975496 let srt = wrong_kind_sort_of_constructor lid.txt in
54985497 let ctx = Expression explanation in
54995498 let error = Wrong_expected_kind(srt, ctx, ty_expected) in
55005500- raise (Error (loc, env, error))
54995499+ raise (Error (sexp.pexp_loc, env, error))
55015500 in
55025501 let constrs =
55035502 Env.lookup_all_constructors ~loc:lid.loc Env.Positive lid.txt env
···55115510 match sarg with
55125511 None -> []
55135512 | Some {pexp_desc = Pexp_tuple sel} when
55145514- constr.cstr_arity > 1 || Builtin_attributes.explicit_arity attrs
55135513+ constr.cstr_arity > 1
55145514+ || Builtin_attributes.explicit_arity sexp.pexp_attributes
55155515 -> sel
55165516 | Some se -> [se] in
55175517 if List.length sargs <> constr.cstr_arity then
55185518- raise(Error(loc, env, Constructor_arity_mismatch
55195519- (lid.txt, constr.cstr_arity, List.length sargs)));
55185518+ raise(Error(sexp.pexp_loc, env,
55195519+ Constructor_arity_mismatch
55205520+ (lid.txt, constr.cstr_arity, List.length sargs)));
55205521 let separate = !Clflags.principal || Env.has_local_constraints env in
55215522 let ty_args, ty_res, texp =
55225523 with_local_level_generalize_structure_if separate begin fun () ->
···55285529 let texp =
55295530 re {
55305531 exp_desc = Texp_construct(lid, constr, []);
55315531- exp_loc = loc; exp_extra = [];
55325532+ exp_loc = sexp.pexp_loc; exp_extra = [];
55325533 exp_type = ty_res;
55335533- exp_attributes = attrs;
55345534+ exp_attributes = sexp.pexp_attributes;
55345535 exp_env = env } in
55355536 (ty_args, ty_res, texp)
55365537 end
55375538 in
55385539 with_explanation explanation (fun () ->
55395539- unify_exp env {texp with exp_type = instance ty_res}
55405540+ unify_exp ~sexp env {texp with exp_type = instance ty_res}
55405541 (instance ty_expected));
55415542 (ty_args, ty_res, texp)
55425543 end
···55475548 | _ -> assert false
55485549 in
55495550 let texp = {texp with exp_type = ty_res} in
55505550- if not separate then unify_exp env texp (instance ty_expected);
55515551+ if not separate then unify_exp ~sexp env texp (instance ty_expected);
55515552 let recarg =
55525553 match constr.cstr_inlined with
55535554 | None -> Rejected
···55585559 Pexp_record (_, (Some {pexp_desc = Pexp_ident _}| None))}] ->
55595560 Required
55605561 | _ ->
55615561- raise (Error(loc, env, Inlined_record_expected))
55625562+ raise (Error(sexp.pexp_loc, env, Inlined_record_expected))
55625563 end
55635564 in
55645565 let args =
···55675568 if constr.cstr_private = Private then
55685569 begin match constr.cstr_tag with
55695570 | Cstr_extension _ ->
55705570- raise(Error(loc, env, Private_constructor (constr, ty_res)))
55715571+ raise(Error(sexp.pexp_loc, env, Private_constructor (constr, ty_res)))
55715572 | Cstr_constant _ | Cstr_block _ | Cstr_unboxed ->
55725572- raise (Error(loc, env, Private_type ty_res));
55735573+ raise (Error(sexp.pexp_loc, env, Private_type ty_res));
55735574 end;
55745575 (* NOTE: shouldn't we call "re" on this final expression? -- AF *)
55755576 { texp with
···56065607 if !Clflags.strict_sequence then
56075608 let expected_ty = instance Predef.type_unit in
56085609 with_explanation explanation (fun () ->
56095609- unify_exp env exp expected_ty)
56105610+ unify_exp ~sexp env exp expected_ty)
56105611 else begin
56115612 check_partial_application ~statement:true exp;
56125613 enforce_current_level env ty
···64216422 | _ -> None
64226423 ))
6423642464256425+(** More precise denomination for type errors. Used by messages:
64266426+64276427+ - [This <denom> ...]
64286428+ - [The <denom> "foo" ...] *)
64296429+let pp_exp_denom ppf pexp =
64306430+ let d = pp_print_string ppf in
64316431+ let d_expression = fprintf ppf "%a expression" Style.inline_code in
64326432+ match pexp.pexp_desc with
64336433+ | Pexp_constant _ -> d "constant"
64346434+ | Pexp_ident _ -> d "value"
64356435+ | Pexp_construct _ | Pexp_variant _ -> d "constructor"
64366436+ | Pexp_field _ -> d "field access"
64376437+ | Pexp_send _ -> d "method call"
64386438+ | Pexp_while _ -> d_expression "while"
64396439+ | Pexp_for _ -> d_expression "for"
64406440+ | Pexp_ifthenelse _ -> d_expression "if-then-else"
64416441+ | Pexp_match _ -> d_expression "match"
64426442+ | Pexp_try _ -> d_expression "try-with"
64436443+ | _ -> d "expression"
64446444+64456445+(** Implements the "This expression" message, printing the expression if it
64466446+ should be according to {!Parsetree.Doc.nominal_exp}. *)
64476447+let report_this_pexp_has_type denom ppf exp =
64486448+ let denom ppf =
64496449+ match denom, exp with
64506450+ | Some d, _ -> fprintf ppf "%s" d
64516451+ | None, Some exp -> pp_exp_denom ppf exp
64526452+ | None, None -> fprintf ppf "expression"
64536453+ in
64546454+ let nexp = Option.bind exp Pprintast.Doc.nominal_exp in
64556455+ match nexp with
64566456+ | Some nexp ->
64576457+ fprintf ppf "The %t %a has type" denom (Style.as_inline_code pp_doc) nexp
64586458+ | _ -> fprintf ppf "This %t has type" denom
64596459+64606460+let report_this_texp_has_type denom ppf texp =
64616461+ report_this_pexp_has_type denom ppf (Some (Untypeast.untype_expression texp))
64626462+64246463(* Hint on type error on integer literals
64256464 To avoid confusion, it is disabled on float literals
64266465 and when the expected type is `int` *)
···6471651064726511let report_expr_type_clash_hints exp diff =
64736512 match exp with
64746474- | Some (Pexp_constant const) -> report_literal_type_constraint const diff
64756475- | Some (Pexp_apply _) -> report_partial_application diff
64766476- | _ -> []
65136513+ | Some exp -> begin
65146514+ match exp.pexp_desc with
65156515+ | Pexp_constant const -> report_literal_type_constraint const diff
65166516+ | Pexp_apply _ -> report_partial_application diff
65176517+ | _ -> []
65186518+ end
65196519+ | None -> []
6477652064786521let report_pattern_type_clash_hints pat diff =
64796522 match pat with
···65156558 Printtyp.report_unification_error ppf env err
65166559 ?type_expected_explanation txt1 txt2
65176560 ) ()
65186518-65196519-let report_this_function ppf funct =
65206520- match Typedtree.nominal_exp_doc Printtyp.longident funct with
65216521- | None -> Fmt.fprintf ppf "This function"
65226522- | Some name ->
65236523- Fmt.fprintf ppf "The function %a"
65246524- (Style.as_inline_code Fmt.pp_doc) name
6525656165266562let report_too_many_arg_error ~funct ~func_ty ~previous_arg_loc
65276563 ~extra_arg_loc ~returns_unit loc =
···65496585 msg ~loc:extra_arg_loc "This extra argument is not expected.";
65506586 ] in
65516587 errorf ~loc:app_loc ~sub
65526552- "@[<v>@[<2>%a has type@ %a@]\
65886588+ "@[<v>@[<2>%a@ %a@]\
65536589 @ It is applied to too many arguments@]"
65546554- report_this_function funct Printtyp.type_expr func_ty
65906590+ (report_this_texp_has_type (Some "function")) funct
65916591+ Printtyp.type_expr func_ty
6555659265566593let msg = Fmt.doc_printf
65576594···65966633 report_unification_error ~loc ~sub env err
65976634 ~type_expected_explanation:
65986635 (report_type_expected_explanation_opt explanation)
65996599- (msg "This expression has type")
66366636+ (msg "%a" (report_this_pexp_has_type None) exp)
66006637 (msg "but an expression was expected of type");
66016638 | Function_arity_type_clash {
66026639 syntactic_arity; type_constraint; trace = { trace };
+1-1
typing/typecore.mli
···163163 | Orpat_vars of Ident.t * Ident.t list
164164 | Expr_type_clash of
165165 Errortrace.unification_error * type_forcing_context option
166166- * Parsetree.expression_desc option
166166+ * Parsetree.expression option
167167 | Function_arity_type_clash of
168168 { syntactic_arity : int;
169169 type_constraint : type_expr;
-35
typing/typedtree.ml
···893893 combine_opts (into cpat) exns1 exns2
894894 in
895895 split_pattern pat
896896-897897-(* Expressions are considered nominal if they can be used as the subject of a
898898- sentence or action. In practice, we consider that an expression is nominal
899899- if they satisfy one of:
900900- - Similar to an identifier: words separated by '.' or '#'.
901901- - Do not contain spaces when printed.
902902-*)
903903-let nominal_exp_doc lid t =
904904- let open Format_doc.Doc in
905905- let longident l = Format_doc.doc_printer lid l.Location.txt in
906906- let rec nominal_exp_doc doc exp =
907907- match exp.exp_desc with
908908- | _ when exp.exp_attributes <> [] -> None
909909- | Texp_ident (_,l,_) ->
910910- Some (longident l doc)
911911- | Texp_instvar (_,_,s) ->
912912- Some (string s.Location.txt doc)
913913- | Texp_constant _ -> assert false
914914- | Texp_variant (lbl, None) ->
915915- Some (printf "`%s" lbl doc)
916916- | Texp_construct (l, _, []) -> Some (longident l doc)
917917- | Texp_field (parent, lbl, _) ->
918918- Option.map
919919- (printf ".%t" (longident lbl))
920920- (nominal_exp_doc doc parent)
921921- | Texp_send (parent, meth) ->
922922- let name = match meth with
923923- | Tmeth_name name -> name
924924- | Tmeth_val id | Tmeth_ancestor (id,_) -> Ident.name id in
925925- Option.map
926926- (printf "#%s" name)
927927- (nominal_exp_doc doc parent)
928928- | _ -> None
929929- in
930930- nominal_exp_doc empty t
-6
typing/typedtree.mli
···919919(** Splits an or pattern into its value (left) and exception (right) parts. *)
920920val split_pattern:
921921 computation general_pattern -> pattern option * pattern option
922922-923923-(** Returns a format document if the expression reads nicely as the subject of a
924924- sentence in a error message. *)
925925-val nominal_exp_doc :
926926- Longident.t Format_doc.printer -> expression
927927- -> Format_doc.t option