The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #12182 from Julow/print-expr-type-clash

Improve the type clash error message

authored by

Florian Angeletti and committed by
GitHub
9a982c0d bbc7ce7e

+430 -302
+2 -3
.depend
··· 1558 1558 typing/printpat.cmi \ 1559 1559 typing/primitive.cmi \ 1560 1560 typing/predef.cmi \ 1561 + parsing/pprintast.cmi \ 1561 1562 typing/persistent_env.cmi \ 1562 1563 typing/path.cmi \ 1563 1564 parsing/parsetree.cmi \ ··· 1592 1593 typing/printpat.cmx \ 1593 1594 typing/primitive.cmx \ 1594 1595 typing/predef.cmx \ 1596 + parsing/pprintast.cmx \ 1595 1597 typing/persistent_env.cmx \ 1596 1598 typing/path.cmx \ 1597 1599 parsing/parsetree.cmi \ ··· 1838 1840 parsing/longident.cmi \ 1839 1841 parsing/location.cmi \ 1840 1842 typing/ident.cmi \ 1841 - utils/format_doc.cmi \ 1842 1843 typing/env.cmi \ 1843 1844 parsing/asttypes.cmi \ 1844 1845 typing/typedtree.cmi ··· 1852 1853 parsing/longident.cmx \ 1853 1854 parsing/location.cmx \ 1854 1855 typing/ident.cmx \ 1855 - utils/format_doc.cmx \ 1856 1856 typing/env.cmx \ 1857 1857 parsing/asttypes.cmx \ 1858 1858 typing/typedtree.cmi ··· 1866 1866 parsing/longident.cmi \ 1867 1867 parsing/location.cmi \ 1868 1868 typing/ident.cmi \ 1869 - utils/format_doc.cmi \ 1870 1869 typing/env.cmi \ 1871 1870 parsing/asttypes.cmi 1872 1871 typing/typemod.cmo : \
+7
Changes
··· 274 274 - #13255: Re-enable warning 34 for unused locally abstract types 275 275 (Nick Roberts, review by Chris Casinghino and Florian Angeletti) 276 276 277 + - #12182: Improve the type clash error message. 278 + For example, this message: 279 + This expression has type ... 280 + is changed into: 281 + The constant "42" has type ... 282 + (Jules Aguillon, review by Gabriel Scherer and Florian Angeletti) 283 + 277 284 ### Internal/compiler-libs changes: 278 285 279 286 - #11129, #11148: enforce that ppxs do not produce `parsetree`s with
+42
parsing/pprintast.ml
··· 136 136 137 137 let tyvar ppf s = 138 138 Format_doc.fprintf ppf "%s" (tyvar_of_name s) 139 + 140 + (* Expressions are considered nominal if they can be used as the subject of a 141 + sentence or action. In practice, we consider that an expression is nominal 142 + if they satisfy one of: 143 + - Similar to an identifier: words separated by '.' or '#'. 144 + - Do not contain spaces when printed. 145 + - Is a constant that is short enough. 146 + *) 147 + let nominal_exp t = 148 + let open Format_doc.Doc in 149 + let longident l = Format_doc.doc_printer longident l.Location.txt in 150 + let rec nominal_exp doc exp = 151 + match exp.pexp_desc with 152 + | _ when exp.pexp_attributes <> [] -> None 153 + | Pexp_ident l -> 154 + Some (longident l doc) 155 + | Pexp_variant (lbl, None) -> 156 + Some (printf "`%s" lbl doc) 157 + | Pexp_construct (l, None) -> 158 + Some (longident l doc) 159 + | Pexp_field (parent, lbl) -> 160 + Option.map 161 + (printf ".%t" (longident lbl)) 162 + (nominal_exp doc parent) 163 + | Pexp_send (parent, meth) -> 164 + Option.map 165 + (printf "#%s" meth.txt) 166 + (nominal_exp doc parent) 167 + (* String constants are syntactically too complex. For example, the 168 + quotes conflict with the 'inline_code' style and they might contain 169 + spaces. *) 170 + | Pexp_constant { pconst_desc = Pconst_string _; _ } -> None 171 + (* Char, integer and float constants are nominal. *) 172 + | Pexp_constant { pconst_desc = Pconst_char c; _ } -> 173 + Some (msg "%C" c) 174 + | Pexp_constant 175 + { pconst_desc = Pconst_integer (cst, suf) | Pconst_float (cst, suf); 176 + _ } -> 177 + Some (msg "%s%t" cst (option char suf)) 178 + | _ -> None 179 + in 180 + nominal_exp empty t 139 181 end 140 182 141 183 let longident ppf l = Format_doc.compat Doc.longident ppf l
+4
parsing/pprintast.mli
··· 64 64 module Doc:sig 65 65 val longident: Longident.t Format_doc.printer 66 66 val tyvar: string Format_doc.printer 67 + 68 + (** Returns a format document if the expression reads nicely as the subject 69 + of a sentence in a error message. *) 70 + val nominal_exp : Parsetree.expression -> Format_doc.t option 67 71 end
+2 -2
testsuite/tests/effect-syntax/error_messages.ml
··· 24 24 Line 3, characters 21-22: 25 25 3 | | effect A _, k -> k 26 26 ^ 27 - Error: This expression has type "(%eff, unit) continuation" 27 + Error: The value "k" has type "(%eff, unit) continuation" 28 28 but an expression was expected of type "unit" 29 29 |}, Principal{| 30 30 Line 3, characters 21-22: 31 31 3 | | effect A _, k -> k 32 32 ^ 33 - Error: This expression has type "(int, unit) continuation" 33 + Error: The value "k" has type "(int, unit) continuation" 34 34 but an expression was expected of type "unit" 35 35 This instance of "int" is ambiguous: 36 36 it would escape the scope of its equation
+2 -3
testsuite/tests/formatting/margins.ocaml.reference
··· 1 1 Line 2, characters 4-9: 2 2 2 | 1 + "foo";; 3 3 ^^^^^ 4 - Error: This expression has type 4 + Error: This constant has type 5 5 "string" 6 6 but an expression was expected of type 7 7 "int" 8 8 Line 2, characters 4-9: 9 9 2 | 1 + "foo";; 10 10 ^^^^^ 11 - Error: This expression has type "string" but an expression was expected of type 12 - "int" 11 + Error: This constant has type "string" but an expression was expected of type "int" 13 12
+1 -1
testsuite/tests/generalized-open/gpr1506.ml
··· 360 360 Line 1, characters 42-43: 361 361 1 | let x = let open struct type t = T end in T 362 362 ^ 363 - Error: This expression has type "t" but an expression was expected of type "'a" 363 + Error: The constructor "T" has type "t" but an expression was expected of type "'a" 364 364 The type constructor "t" would escape its scope 365 365 |}] 366 366
+1 -2
testsuite/tests/hidden_includes/not_included.ocamlc.reference
··· 1 1 File "libc/c1.ml", line 1, characters 8-11: 2 2 1 | let x = B.x + 1 3 3 ^^^ 4 - Error: This expression has type "A.t" but an expression was expected of type 5 - "int" 4 + Error: The value "B.x" has type "A.t" but an expression was expected of type "int" 6 5 Type "A.t" is abstract because no corresponding cmi file was found 7 6 in path.
+2 -2
testsuite/tests/let-syntax/let_syntax.ml
··· 187 187 Line 3, characters 13-14: 188 188 3 | let+ x = 1 in 189 189 ^ 190 - Error: This expression has type "int" but an expression was expected of type 190 + Error: The constant "1" has type "int" but an expression was expected of type 191 191 "bool" 192 192 |}];; 193 193 ··· 215 215 Line 3, characters 13-14: 216 216 3 | let+ x = 1 217 217 ^ 218 - Error: This expression has type "int" but an expression was expected of type 218 + Error: The constant "1" has type "int" but an expression was expected of type 219 219 "float" 220 220 Hint: Did you mean "1."? 221 221 |}];;
+3 -3
testsuite/tests/printing-types/existentials.ml
··· 15 15 Line 6, characters 13-14: 16 16 6 | | Foo a -> a + 1 17 17 ^ 18 - Error: This expression has type "$a * $b * $c * $d * $e * $f" 18 + Error: The value "a" has type "$a * $b * $c * $d * $e * $f" 19 19 but an expression was expected of type "int" 20 20 Hint: "$a", "$b", "$c", "$d", "$e" and "$f" are existential types 21 21 bound by the constructor "Foo". ··· 48 48 Line 13, characters 46-47: 49 49 13 | let x = (a1, a2, a3, a4, a5, a6, a7) in x + 1 50 50 ^ 51 - Error: This expression has type "$a * $a1 * $a2 * $a3 * $a4 * $a5 * $a6" 51 + Error: The value "x" has type "$a * $a1 * $a2 * $a3 * $a4 * $a5 * $a6" 52 52 but an expression was expected of type "int" 53 53 Hint: "$a" is an existential type bound by the constructor "Foo1". 54 54 Hint: "$a1" is an existential type bound by the constructor "Foo2". ··· 86 86 Line 13, characters 46-47: 87 87 13 | let x = (a1, a2, a3, a4, a5, a6, a7) in x + 1 88 88 ^ 89 - Error: This expression has type 89 + Error: The value "x" has type 90 90 "($a * $b * $c * $d * $e * $f) * 91 91 ($a1 * $b1 * $c1 * $d1 * $e1 * $f1) * 92 92 ($a2 * $b2 * $c2 * $d2 * $e2 * $f2) *
+1 -1
testsuite/tests/tool-caml-tex/redirections.reference
··· 9 9 $\?$ 1 + <<2.>> ;; 10 10 \end{camlinput} 11 11 \begin{camlerror} 12 - Error: This expression has type float but an expression was expected of type 12 + Error: The constant 2. has type float but an expression was expected of type 13 13 int 14 14 \end{camlerror} 15 15 \end{caml}
+2 -2
testsuite/tests/tool-expect-test/clean_typer.ml
··· 64 64 Line 1, characters 14-17: 65 65 1 | let f2 = ffoo bar;; 66 66 ^^^ 67 - Error: This expression has type "Variants.bar M.t" 67 + Error: The value "bar" has type "Variants.bar M.t" 68 68 but an expression was expected of type "Variants.foo M.t" 69 69 Type "Variants.bar" = "[ `Bar ]" is not compatible with type "Variants.foo" 70 70 The first variant type does not allow tag(s) "`Foo" ··· 75 75 Line 1, characters 14-17: 76 76 1 | let f3 = fbar foo;; 77 77 ^^^ 78 - Error: This expression has type "Variants.foo M.t" 78 + Error: The value "foo" has type "Variants.foo M.t" 79 79 but an expression was expected of type "Variants.bar M.t" 80 80 Type "Variants.foo" is not compatible with type "Variants.bar" = "[ `Bar ]" 81 81 The second variant type does not allow tag(s) "`Foo"
+2 -2
testsuite/tests/tool-ocamlc-locations/marshalled.compilers.reference
··· 1 1 File "foo.ml", line 1, characters 14-18: 2 2 1 | let x : int = true 3 3 ^^^^ 4 - Error: This expression has type "bool" but an expression was expected of type 5 - "int" 4 + Error: The constructor "\#true" has type "bool" 5 + but an expression was expected of type "int"
+2 -2
testsuite/tests/tool-toplevel/error_highlighting.compilers.reference
··· 22 22 Line 3, characters 8-9: 23 23 3 | let y = 1 +. 2. in 24 24 ^ 25 - Error: This expression has type "int" but an expression was expected of type 25 + Error: The constant "1" has type "int" but an expression was expected of type 26 26 "float" 27 27 Hint: Did you mean "1."? 28 28 Line 4, characters 2-4: ··· 42 42 Line 2, characters 12-17: 43 43 2 | let x = 1 + "abc" in 44 44 ^^^^^ 45 - Error: This expression has type "string" but an expression was expected of type 45 + Error: This constant has type "string" but an expression was expected of type 46 46 "int" 47 47 File "error_highlighting_use1.ml", line 1, characters 8-15: 48 48 1 | let x = (1 + 2) +. 3. in ();;
+2 -2
testsuite/tests/tool-toplevel/multi_phrase_line.compilers.reference
··· 21 21 Line 2, characters 16-20: 22 22 2 | 11;; let x = 12+true;; 13;; (* Type error in second phrase. *) 23 23 ^^^^ 24 - Error: This expression has type "bool" but an expression was expected of type 25 - "int" 24 + Error: The constructor "\#true" has type "bool" 25 + but an expression was expected of type "int" 26 26 # Line 2, characters 0-22: 27 27 2 | match 14 with 15 -> ();; 16;; 17;; (* Warning + run-time error in 1st phrase. *) 28 28 ^^^^^^^^^^^^^^^^^^^^^^
+4 -5
testsuite/tests/tool-toplevel/redefinition_hints.compilers.reference
··· 14 14 Line 2, characters 4-5: 15 15 2 | x = y;; 16 16 ^ 17 - Error: This expression has type "(u * v * (module S)) M.t" 17 + Error: The value "y" has type "(u * v * (module S)) M.t" 18 18 but an expression was expected of type 19 19 "(u/2 * v/2 * (module S/2)) M/2.t" 20 20 Hint: The types "v" and "u" have been defined multiple times in this ··· 35 35 Line 2, characters 4-5: 36 36 2 | a = b;; 37 37 ^ 38 - Error: This expression has type "a/2" but an expression was expected of type 39 - "a/3" 38 + Error: The value "b" has type "a/2" but an expression was expected of type "a/3" 40 39 Hint: The type "a" has been defined multiple times in this toplevel 41 40 session. Some toplevel values still refer to old versions of this 42 41 type. Did you try to redefine them? 43 42 Line 1, characters 4-5: 44 43 1 | a = c;; 45 44 ^ 46 - Error: This expression has type "a" but an expression was expected of type "a/3" 45 + Error: The value "c" has type "a" but an expression was expected of type "a/3" 47 46 Hint: The type "a" has been defined multiple times in this toplevel 48 47 session. Some toplevel values still refer to old versions of this 49 48 type. Did you try to redefine them? 50 49 Line 1, characters 4-5: 51 50 1 | b = c;; 52 51 ^ 53 - Error: This expression has type "a" but an expression was expected of type "a/2" 52 + Error: The value "c" has type "a" but an expression was expected of type "a/2" 54 53 Hint: The type "a" has been defined multiple times in this toplevel 55 54 session. Some toplevel values still refer to old versions of this 56 55 type. Did you try to redefine them?
+1 -1
testsuite/tests/tool-toplevel/use_command.ml
··· 20 20 File "(command-output)", line 1, characters 5-6: 21 21 1 | 1 :: x 22 22 ^ 23 - Error: This expression has type "int" but an expression was expected of type 23 + Error: The value "x" has type "int" but an expression was expected of type 24 24 "int list" 25 25 |}];;
+16 -17
testsuite/tests/typing-core-bugs/const_int_hint.ml
··· 7 7 Line 1, characters 19-20: 8 8 1 | let _ = Int32.(add 1 2l);; 9 9 ^ 10 - Error: This expression has type "int" but an expression was expected of type 10 + Error: The constant "1" has type "int" but an expression was expected of type 11 11 "int32" 12 12 Hint: Did you mean "1l"? 13 13 |}] ··· 17 17 Line 1, characters 29-31: 18 18 1 | let _ : int32 * int32 = 42l, 43;; 19 19 ^^ 20 - Error: This expression has type "int" but an expression was expected of type 20 + Error: The constant "43" has type "int" but an expression was expected of type 21 21 "int32" 22 22 Hint: Did you mean "43l"? 23 23 |}] ··· 27 27 Line 1, characters 33-35: 28 28 1 | let _ : int32 * nativeint = 42l, 43;; 29 29 ^^ 30 - Error: This expression has type "int" but an expression was expected of type 30 + Error: The constant "43" has type "int" but an expression was expected of type 31 31 "nativeint" 32 32 Hint: Did you mean "43n"? 33 33 |}] ··· 37 37 Line 1, characters 15-16: 38 38 1 | let _ = min 6L 7;; 39 39 ^ 40 - Error: This expression has type "int" but an expression was expected of type 40 + Error: The constant "7" has type "int" but an expression was expected of type 41 41 "int64" 42 42 Hint: Did you mean "7L"? 43 43 |}] ··· 47 47 Line 1, characters 16-19: 48 48 1 | let _ : float = 123;; 49 49 ^^^ 50 - Error: This expression has type "int" but an expression was expected of type 50 + Error: The constant "123" has type "int" but an expression was expected of type 51 51 "float" 52 52 Hint: Did you mean "123."? 53 53 |}] ··· 60 60 Line 2, characters 19-20: 61 61 2 | let _ = Int32.(add x 2l);; 62 62 ^ 63 - Error: This expression has type "int" but an expression was expected of type 64 - "int32" 63 + Error: The value "x" has type "int" but an expression was expected of type "int32" 65 64 |}] 66 65 67 66 (* pattern *) ··· 95 94 Line 1, characters 16-18: 96 95 1 | let _ : int32 = 1L;; 97 96 ^^ 98 - Error: This expression has type "int64" but an expression was expected of type 97 + Error: The constant "1L" has type "int64" but an expression was expected of type 99 98 "int32" 100 99 Hint: Did you mean "1l"? 101 100 |}] ··· 104 103 Line 1, characters 16-18: 105 104 1 | let _ : float = 1L;; 106 105 ^^ 107 - Error: This expression has type "int64" but an expression was expected of type 106 + Error: The constant "1L" has type "int64" but an expression was expected of type 108 107 "float" 109 108 Hint: Did you mean "1."? 110 109 |}] ··· 113 112 Line 1, characters 16-18: 114 113 1 | let _ : int64 = 1n;; 115 114 ^^ 116 - Error: This expression has type "nativeint" 115 + Error: The constant "1n" has type "nativeint" 117 116 but an expression was expected of type "int64" 118 117 Hint: Did you mean "1L"? 119 118 |}] ··· 122 121 Line 1, characters 20-22: 123 122 1 | let _ : nativeint = 1l;; 124 123 ^^ 125 - Error: This expression has type "int32" but an expression was expected of type 124 + Error: The constant "1l" has type "int32" but an expression was expected of type 126 125 "nativeint" 127 126 Hint: Did you mean "1n"? 128 127 |}] ··· 133 132 Line 1, characters 16-18: 134 133 1 | let _ : int64 = 0.;; 135 134 ^^ 136 - Error: This expression has type "float" but an expression was expected of type 135 + Error: The constant "0." has type "float" but an expression was expected of type 137 136 "int64" 138 137 |}] 139 138 let _ : int = 1L;; ··· 141 140 Line 1, characters 14-16: 142 141 1 | let _ : int = 1L;; 143 142 ^^ 144 - Error: This expression has type "int64" but an expression was expected of type 143 + Error: The constant "1L" has type "int64" but an expression was expected of type 145 144 "int" 146 145 |}] 147 146 ··· 152 151 Line 1, characters 23-28: 153 152 1 | let _ : int64 = min 0L 1_000;; 154 153 ^^^^^ 155 - Error: This expression has type "int" but an expression was expected of type 154 + Error: The constant "1_000" has type "int" but an expression was expected of type 156 155 "int64" 157 156 Hint: Did you mean "1_000L"? 158 157 |}] ··· 161 160 Line 1, characters 36-44: 162 161 1 | let _ : nativeint * nativeint = 0n, 0xAA_BBL;; 163 162 ^^^^^^^^ 164 - Error: This expression has type "int64" but an expression was expected of type 165 - "nativeint" 163 + Error: The constant "0xAA_BBL" has type "int64" 164 + but an expression was expected of type "nativeint" 166 165 Hint: Did you mean "0xAA_BBn"? 167 166 |}] 168 167 let _ : int32 -> int32 = function ··· 193 192 Line 1, characters 49-55: 194 193 1 | type t1 = {f1: int32};; let _ = fun x -> x.f1 <- 1_000n;; 195 194 ^^^^^^ 196 - Error: This expression has type "nativeint" 195 + Error: The constant "1_000n" has type "nativeint" 197 196 but an expression was expected of type "int32" 198 197 Hint: Did you mean "1_000l"? 199 198 |}]
+16 -19
testsuite/tests/typing-core-bugs/type_expected_explanation.ml
··· 9 9 Line 1, characters 3-4: 10 10 1 | if 3 then ();; 11 11 ^ 12 - Error: This expression has type "int" but an expression was expected of type 12 + Error: The constant "3" has type "int" but an expression was expected of type 13 13 "bool" 14 14 because it is in the condition of an if-statement 15 15 |}];; ··· 20 20 Line 1, characters 45-46: 21 21 1 | fun b -> if true then (print_int b) else (if b then ());; 22 22 ^ 23 - Error: This expression has type "int" but an expression was expected of type 24 - "bool" 25 - because it is in the condition of an if-statement 23 + Error: The value "b" has type "int" but an expression was expected of type " 24 + bool" because it is in the condition of an if-statement 26 25 |}];; 27 26 28 27 (* Left-to-right bias is still there: if we swap the branches, the new error ··· 33 32 Line 1, characters 53-54: 34 33 1 | fun b -> if true then (if b then ()) else (print_int b);; 35 34 ^ 36 - Error: This expression has type "bool" but an expression was expected of type 37 - "int" 35 + Error: The value "b" has type "bool" but an expression was expected of type "int" 38 36 |}];; 39 37 40 38 if (let x = 3 in x) then ();; ··· 43 41 Line 1, characters 17-18: 44 42 1 | if (let x = 3 in x) then ();; 45 43 ^ 46 - Error: This expression has type "int" but an expression was expected of type 47 - "bool" 48 - because it is in the condition of an if-statement 44 + Error: The value "x" has type "int" but an expression was expected of type " 45 + bool" because it is in the condition of an if-statement 49 46 |}];; 50 47 51 48 if (if true then 3 else 4) then ();; ··· 54 51 Line 1, characters 17-18: 55 52 1 | if (if true then 3 else 4) then ();; 56 53 ^ 57 - Error: This expression has type "int" but an expression was expected of type 54 + Error: The constant "3" has type "int" but an expression was expected of type 58 55 "bool" 59 56 because it is in the condition of an if-statement 60 57 |}];; ··· 65 62 Line 1, characters 13-14: 66 63 1 | if true then 3;; 67 64 ^ 68 - Error: This expression has type "int" but an expression was expected of type 65 + Error: The constant "3" has type "int" but an expression was expected of type 69 66 "unit" 70 67 because it is in the result of a conditional with no else branch 71 68 |}];; ··· 86 83 Line 1, characters 6-8: 87 84 1 | while 42 do () done;; 88 85 ^^ 89 - Error: This expression has type "int" but an expression was expected of type 86 + Error: The constant "42" has type "int" but an expression was expected of type 90 87 "bool" 91 88 because it is in the condition of a while-loop 92 89 |}];; ··· 99 96 Line 1, characters 14-37: 100 97 1 | while true do (if true then 3 else 4) done;; 101 98 ^^^^^^^^^^^^^^^^^^^^^^^ 102 - Error: This expression has type "int" but an expression was expected of type 103 - "unit" 99 + Error: This "if-then-else" expression has type "int" 100 + but an expression was expected of type "unit" 104 101 because it is in the body of a while-loop 105 102 |}];; 106 103 ··· 110 107 Line 1, characters 8-10: 111 108 1 | for i = 3. to 4 do () done;; 112 109 ^^ 113 - Error: This expression has type "float" but an expression was expected of type 110 + Error: The constant "3." has type "float" but an expression was expected of type 114 111 "int" 115 112 because it is in a for-loop start index 116 113 |}];; ··· 121 118 Line 1, characters 13-15: 122 119 1 | for i = 3 to 4. do () done;; 123 120 ^^ 124 - Error: This expression has type "float" but an expression was expected of type 121 + Error: The constant "4." has type "float" but an expression was expected of type 125 122 "int" 126 123 because it is in a for-loop stop index 127 124 |}];; ··· 134 131 Line 1, characters 18-41: 135 132 1 | for i = 0 to 0 do (if true then 3 else 4) done;; 136 133 ^^^^^^^^^^^^^^^^^^^^^^^ 137 - Error: This expression has type "int" but an expression was expected of type 138 - "unit" 134 + Error: This "if-then-else" expression has type "int" 135 + but an expression was expected of type "unit" 139 136 because it is in the body of a for-loop 140 137 |}];; 141 138 ··· 145 142 Line 1, characters 7-9: 146 143 1 | assert 12;; 147 144 ^^ 148 - Error: This expression has type "int" but an expression was expected of type 145 + Error: The constant "12" has type "int" but an expression was expected of type 149 146 "bool" 150 147 because it is in the condition of an assertion 151 148 |}];;
+6 -6
testsuite/tests/typing-core-bugs/unit_fun_hints.ml
··· 11 11 Line 2, characters 10-11: 12 12 2 | let _ = g 3;; (* missing `fun () ->' *) 13 13 ^ 14 - Error: This expression has type "int" but an expression was expected of type 14 + Error: The constant "3" has type "int" but an expression was expected of type 15 15 "unit -> 'a" 16 16 Hint: Did you forget to wrap the expression using "fun () ->"? 17 17 |}];; ··· 28 28 Line 3, characters 3-16: 29 29 3 | print_newline; (* missing unit argument *) 30 30 ^^^^^^^^^^^^^ 31 - Error: This expression has type "unit -> unit" 31 + Error: The value "print_newline" has type "unit -> unit" 32 32 but an expression was expected of type "unit" 33 33 because it is in the left-hand side of a sequence 34 34 Hint: Did you forget to provide "()" as argument? ··· 41 41 Line 2, characters 10-11: 42 42 2 | print_int x;; 43 43 ^ 44 - Error: This expression has type "unit -> int" 44 + Error: The value "x" has type "unit -> int" 45 45 but an expression was expected of type "int" 46 46 Hint: Did you forget to provide "()" as argument? 47 47 |}];; ··· 54 54 Line 3, characters 6-7: 55 55 3 | f = 3;; 56 56 ^ 57 - Error: This expression has type "int" but an expression was expected of type 57 + Error: The constant "3" has type "int" but an expression was expected of type 58 58 "unit -> 'a" 59 59 Hint: Did you forget to wrap the expression using "fun () ->"? 60 60 |}];; ··· 67 67 Line 3, characters 6-7: 68 68 3 | 3 = f;; 69 69 ^ 70 - Error: This expression has type "unit -> 'a" 71 - but an expression was expected of type "int" 70 + Error: The value "f" has type "unit -> 'a" but an expression was expected of type 71 + "int" 72 72 Hint: Did you forget to provide "()" as argument? 73 73 |}]
+1 -1
testsuite/tests/typing-extensions/extensions.ml
··· 231 231 Line 1, characters 10-11: 232 232 1 | let a = A 9 233 233 ^ 234 - Error: This expression has type "int" but an expression was expected of type 234 + Error: The constant "9" has type "int" but an expression was expected of type 235 235 "[> `Var ]" 236 236 |}] 237 237
+1 -1
testsuite/tests/typing-fstclassmod/nondep_instance.ml
··· 46 46 Line 3, characters 21-22: 47 47 3 | Linear_map.scale s x 48 48 ^ 49 - Error: This expression has type "(module Scalar with type t = s)" 49 + Error: The value "s" has type "(module Scalar with type t = s)" 50 50 but an expression was expected of type 51 51 "(module Vector_space with type scalar = 'a and type t = 'b)" 52 52 |}];;
+4 -4
testsuite/tests/typing-fstclassmod/scope_escape.ml
··· 117 117 Line 15, characters 8-10: 118 118 15 | unify () 119 119 ^^ 120 - Error: This expression has type "unit" but an expression was expected of type 121 - "M.t" 120 + Error: The constructor "()" has type "unit" 121 + but an expression was expected of type "M.t" 122 122 |}, Principal{| 123 123 module type S = sig type t val x : t end 124 124 Lines 8-12, characters 4-8: ··· 132 132 Line 15, characters 8-10: 133 133 15 | unify () 134 134 ^^ 135 - Error: This expression has type "unit" but an expression was expected of type 136 - "M.t" 135 + Error: The constructor "()" has type "unit" 136 + but an expression was expected of type "M.t" 137 137 |}];;
+6 -10
testsuite/tests/typing-gadts/ambiguity.ml
··· 18 18 Line 3, characters 29-30: 19 19 3 | | Refl -> if b then x else y 20 20 ^ 21 - Error: This expression has type "b" = "a" but an expression was expected of type 22 - "a" 21 + Error: The value "y" has type "b" = "a" but an expression was expected of type "a" 23 22 This instance of "a" is ambiguous: 24 23 it would escape the scope of its equation 25 24 |}] ··· 33 32 Line 3, characters 29-30: 34 33 3 | | Refl -> if b then x else y 35 34 ^ 36 - Error: This expression has type "b" = "a" but an expression was expected of type 37 - "a" 35 + Error: The value "y" has type "b" = "a" but an expression was expected of type "a" 38 36 This instance of "a" is ambiguous: 39 37 it would escape the scope of its equation 40 38 |}] ··· 48 46 Line 3, characters 29-30: 49 47 3 | | Refl -> if b then x else 0 50 48 ^ 51 - Error: This expression has type "int" but an expression was expected of type 49 + Error: The constant "0" has type "int" but an expression was expected of type 52 50 "a" = "int" 53 51 This instance of "int" is ambiguous: 54 52 it would escape the scope of its equation ··· 63 61 Line 3, characters 29-30: 64 62 3 | | Refl -> if b then x else 0 65 63 ^ 66 - Error: This expression has type "int" but an expression was expected of type 64 + Error: The constant "0" has type "int" but an expression was expected of type 67 65 "a" = "int" 68 66 This instance of "int" is ambiguous: 69 67 it would escape the scope of its equation ··· 79 77 Line 3, characters 16-17: 80 78 3 | | Refl -> [x; y] 81 79 ^ 82 - Error: This expression has type "b" = "a" but an expression was expected of type 83 - "a" 80 + Error: The value "y" has type "b" = "a" but an expression was expected of type "a" 84 81 This instance of "a" is ambiguous: 85 82 it would escape the scope of its equation 86 83 |}] ··· 94 91 Line 3, characters 16-17: 95 92 3 | | Refl -> [x; y] 96 93 ^ 97 - Error: This expression has type "b" = "a" but an expression was expected of type 98 - "a" 94 + Error: The value "y" has type "b" = "a" but an expression was expected of type "a" 99 95 This instance of "a" is ambiguous: 100 96 it would escape the scope of its equation 101 97 |}]
+2 -2
testsuite/tests/typing-gadts/didier.ml
··· 54 54 Line 4, characters 12-13: 55 55 4 | | Bool -> x 56 56 ^ 57 - Error: This expression has type "t" = "bool" 58 - but an expression was expected of type "bool" 57 + Error: The value "x" has type "t" = "bool" but an expression was expected of type 58 + "bool" 59 59 This instance of "bool" is ambiguous: 60 60 it would escape the scope of its equation 61 61 |}];;
+1 -1
testsuite/tests/typing-gadts/or_patterns.ml
··· 632 632 Line 3, characters 13-14: 633 633 3 | | A | B -> 3 (* fails because the equation [a = int] doesn't escape any of 634 634 ^ 635 - Error: This expression has type "int" but an expression was expected of type "a" 635 + Error: The constant "3" has type "int" but an expression was expected of type "a" 636 636 |}] 637 637 638 638 (* Making sure we don't break a frequent pattern of GADTs indexed by polymorphic
+2 -2
testsuite/tests/typing-gadts/packed-module-recasting.ml
··· 482 482 Line 4, characters 2-7: 483 483 4 | M.res;; 484 484 ^^^^^ 485 - Error: This expression has type "b" = "int" 485 + Error: The value "M.res" has type "b" = "int" 486 486 but an expression was expected of type "'a" 487 487 This instance of "int" is ambiguous: 488 488 it would escape the scope of its equation ··· 497 497 Line 4, characters 3-8: 498 498 4 | M.res;; 499 499 ^^^^^ 500 - Error: This expression has type "int" but an expression was expected of type "'a" 500 + Error: The value "M.res" has type "int" but an expression was expected of type "'a" 501 501 This instance of "int" is ambiguous: 502 502 it would escape the scope of its equation 503 503 |}]
+1 -1
testsuite/tests/typing-gadts/pr5689.ml
··· 103 103 Line 7, characters 35-43: 104 104 7 | | (Kind _, Ast_Text txt) -> Text txt 105 105 ^^^^^^^^ 106 - Error: This expression has type "[< inkind > `Nonlink ] inline_t" 106 + Error: This constructor has type "[< inkind > `Nonlink ] inline_t" 107 107 but an expression was expected of type "a inline_t" 108 108 Type "[< inkind > `Nonlink ]" = "[< `Link | `Nonlink > `Nonlink ]" 109 109 is not compatible with type "a" = "[< `Link | `Nonlink ]"
+1 -1
testsuite/tests/typing-gadts/pr5948.ml
··· 42 42 Line 25, characters 23-27: 43 43 25 | | WrapPoly ATag -> intA 44 44 ^^^^ 45 - Error: This expression has type "[< `TagA of 'a ] -> 'a" 45 + Error: The value "intA" has type "[< `TagA of 'a ] -> 'a" 46 46 but an expression was expected of type "a -> int" 47 47 Type "[< `TagA of 'a ]" is not compatible with type 48 48 "a" = "[< `TagA of int | `TagB ]"
+1 -2
testsuite/tests/typing-gadts/pr6174.ml
··· 10 10 Line 3, characters 24-25: 11 11 3 | fun C k -> k (fun x -> x);; 12 12 ^ 13 - Error: This expression has type "$0" but an expression was expected of type 14 - "$1" = "o" 13 + Error: The value "x" has type "$0" but an expression was expected of type "$1" = "o" 15 14 |}];;
+1 -1
testsuite/tests/typing-gadts/pr6980.ml
··· 24 24 Line 11, characters 27-29: 25 25 11 | let g (Aux(Second, f)) = f it;; 26 26 ^^ 27 - Error: This expression has type "[< `Bar | `Foo > `Bar ]" 27 + Error: The value "it" has type "[< `Bar | `Foo > `Bar ]" 28 28 but an expression was expected of type "[< `Bar | `Foo ]" 29 29 The second variant type is bound to "$a", 30 30 it may not allow the tag(s) "`Bar"
+2 -2
testsuite/tests/typing-gadts/pr7374.ml
··· 24 24 Line 7, characters 16-20: 25 25 7 | fun Refl -> Refl 26 26 ^^^^ 27 - Error: This expression has type "(a, a) eq" 27 + Error: The constructor "Refl" has type "(a, a) eq" 28 28 but an expression was expected of type "(a, t) eq" 29 29 Type "a" is not compatible with type "t" = "[ `Rec of 'a ] X.t as 'a" 30 30 |}] ··· 56 56 Line 4, characters 21-25: 57 57 4 | fun Refl Refl -> Refl;; 58 58 ^^^^ 59 - Error: This expression has type "(a, a) eq" 59 + Error: The constructor "Refl" has type "(a, a) eq" 60 60 but an expression was expected of type "(a, a X.t X.t) eq" 61 61 Type "a" = "b X.t" is not compatible with type "a X.t X.t" 62 62 Type "b" is not compatible with type "a X.t"
+1 -1
testsuite/tests/typing-gadts/principality-and-gadts.ml
··· 106 106 Line 3, characters 17-18: 107 107 3 | | IntLit, n -> n+1 108 108 ^ 109 - Error: This expression has type "a" but an expression was expected of type "int" 109 + Error: The value "n" has type "a" but an expression was expected of type "int" 110 110 |}] 111 111 112 112 (**********************)
+26 -26
testsuite/tests/typing-gadts/test.ml
··· 293 293 Line 5, characters 21-22: 294 294 5 | let eval (D x) = x 295 295 ^ 296 - Error: This expression has type "$a t" but an expression was expected of type 297 - "'a" 296 + Error: The value "x" has type "$a t" but an expression was expected of type "'a" 298 297 The type constructor "$a" would escape its scope 299 298 Hint: "$a" is an existential type bound by the constructor "D". 300 299 |}];; ··· 377 376 Line 13, characters 19-20: 378 377 13 | | BoolLit b -> b 379 378 ^ 380 - Error: This expression has type "bool" but an expression was expected of type 379 + Error: The value "b" has type "bool" but an expression was expected of type 381 380 "s" = "bool" 382 381 This instance of "bool" is ambiguous: 383 382 it would escape the scope of its equation ··· 586 585 Line 3, characters 44-45: 587 586 3 | match v with Int -> let y = either 1 x in y 588 587 ^ 589 - Error: This expression has type "int" but an expression was expected of type "'a" 588 + Error: The value "y" has type "int" but an expression was expected of type "'a" 590 589 This instance of "int" is ambiguous: 591 590 it would escape the scope of its equation 592 591 |}];; ··· 704 703 Line 2, characters 14-15: 705 704 2 | fun Eq o -> o 706 705 ^ 707 - Error: This expression has type "< m : a; .. >" 706 + Error: The value "o" has type "< m : a; .. >" 708 707 but an expression was expected of type "< m : b; .. >" 709 708 Type "a" is not compatible with type "b" = "a" 710 709 This instance of "a" is ambiguous: ··· 717 716 Line 2, characters 22-23: 718 717 2 | match eq with Eq -> o ;; (* should fail *) 719 718 ^ 720 - Error: This expression has type "< m : a; .. >" 719 + Error: The value "o" has type "< m : a; .. >" 721 720 but an expression was expected of type "< m : b; .. >" 722 721 Type "a" is not compatible with type "b" = "a" 723 722 This instance of "a" is ambiguous: ··· 757 756 Line 4, characters 44-45: 758 757 4 | let r : < m : b > = match eq with Eq -> o in (* fail with principal *) 759 758 ^ 760 - Error: This expression has type "< m : a >" 761 - but an expression was expected of type "< m : b >" 759 + Error: The value "o" has type "< m : a >" but an expression was expected of type 760 + "< m : b >" 762 761 Type "a" is not compatible with type "b" = "a" 763 762 This instance of "a" is ambiguous: 764 763 it would escape the scope of its equation ··· 773 772 Line 3, characters 44-45: 774 773 3 | let r : < m : b > = match eq with Eq -> o in (* fail *) 775 774 ^ 776 - Error: This expression has type "< m : a; .. >" 775 + Error: The value "o" has type "< m : a; .. >" 777 776 but an expression was expected of type "< m : b >" 778 777 Type "a" is not compatible with type "b" = "a" 779 778 This instance of "a" is ambiguous: ··· 786 785 Line 2, characters 14-15: 787 786 2 | fun Eq o -> o ;; (* fail *) 788 787 ^ 789 - Error: This expression has type "[> `A of a ]" 788 + Error: The value "o" has type "[> `A of a ]" 790 789 but an expression was expected of type "[> `A of b ]" 791 790 Type "a" is not compatible with type "b" = "a" 792 791 This instance of "a" is ambiguous: ··· 799 798 Line 2, characters 22-23: 800 799 2 | match eq with Eq -> v ;; (* should fail *) 801 800 ^ 802 - Error: This expression has type "[> `A of a ]" 801 + Error: The value "v" has type "[> `A of a ]" 803 802 but an expression was expected of type "[> `A of b ]" 804 803 Type "a" is not compatible with type "b" = "a" 805 804 This instance of "a" is ambiguous: ··· 855 854 Line 4, characters 49-50: 856 855 4 | let r : [`A of b | `B] = match eq with Eq -> o in (* fail with principal *) 857 856 ^ 858 - Error: This expression has type "[ `A of a | `B ]" 857 + Error: The value "o" has type "[ `A of a | `B ]" 859 858 but an expression was expected of type "[ `A of b | `B ]" 860 859 Type "a" is not compatible with type "b" = "a" 861 860 This instance of "a" is ambiguous: ··· 871 870 Line 3, characters 49-50: 872 871 3 | let r : [`A of b | `B] = match eq with Eq -> o in (* fail *) 873 872 ^ 874 - Error: This expression has type "[> `A of a | `B ]" 873 + Error: The value "o" has type "[> `A of a | `B ]" 875 874 but an expression was expected of type "[ `A of b | `B ]" 876 875 Type "a" is not compatible with type "b" = "a" 877 876 This instance of "a" is ambiguous: ··· 1019 1018 Line 6, characters 17-19: 1020 1019 6 | function Eq -> Eq (* fail *) 1021 1020 ^^ 1022 - Error: This expression has type "(a, a) eq" 1021 + Error: The constructor "Eq" has type "(a, a) eq" 1023 1022 but an expression was expected of type "(a, b) eq" 1024 1023 Type "a" is not compatible with type "b" 1025 1024 |}];; ··· 1075 1074 Line 10, characters 3-4: 1076 1075 10 | (x:<foo:int>) 1077 1076 ^ 1078 - Error: This expression has type "t" = "< foo : int; .. >" 1077 + Error: The value "x" has type "t" = "< foo : int; .. >" 1079 1078 but an expression was expected of type "< foo : int >" 1080 1079 Type "$0" = "< bar : int; .. >" is not compatible with type "< >" 1081 1080 The second object type has no method "bar" ··· 1089 1088 Line 3, characters 3-4: 1090 1089 3 | (x:<foo:int;bar:int>) 1091 1090 ^ 1092 - Error: This expression has type "t" = "< foo : int; .. >" 1091 + Error: The value "x" has type "t" = "< foo : int; .. >" 1093 1092 but an expression was expected of type "< bar : int; foo : int >" 1094 1093 Type "$0" = "< bar : int; .. >" is not compatible with type "< bar : int >" 1095 1094 The first object type has an abstract row, it cannot be closed ··· 1134 1133 Line 3, characters 5-10: 1135 1134 3 | x, x#foo, x#bar 1136 1135 ^^^^^ 1137 - Error: This expression has type "int" but an expression was expected of type "'a" 1136 + Error: The method call "x#foo" has type "int" 1137 + but an expression was expected of type "'a" 1138 1138 This instance of "int" is ambiguous: 1139 1139 it would escape the scope of its equation 1140 1140 |}];; ··· 1202 1202 Line 5, characters 24-25: 1203 1203 5 | if true then a else b 1204 1204 ^ 1205 - Error: This expression has type "b" = "int" 1206 - but an expression was expected of type "a" = "int" 1205 + Error: The value "b" has type "b" = "int" but an expression was expected of type 1206 + "a" = "int" 1207 1207 This instance of "int" is ambiguous: 1208 1208 it would escape the scope of its equation 1209 1209 |}];; ··· 1219 1219 Line 5, characters 24-25: 1220 1220 5 | if true then a else b 1221 1221 ^ 1222 - Error: This expression has type "b" = "int" 1223 - but an expression was expected of type "a" = "int" 1222 + Error: The value "b" has type "b" = "int" but an expression was expected of type 1223 + "a" = "int" 1224 1224 This instance of "int" is ambiguous: 1225 1225 it would escape the scope of its equation 1226 1226 |}];; ··· 1234 1234 Line 4, characters 19-20: 1235 1235 4 | if b then x else y 1236 1236 ^ 1237 - Error: This expression has type "b" = "int" 1238 - but an expression was expected of type "a" = "int" 1237 + Error: The value "y" has type "b" = "int" but an expression was expected of type 1238 + "a" = "int" 1239 1239 This instance of "int" is ambiguous: 1240 1240 it would escape the scope of its equation 1241 1241 |}];; ··· 1248 1248 Line 4, characters 19-20: 1249 1249 4 | if b then y else x 1250 1250 ^ 1251 - Error: This expression has type "a" = "int" 1252 - but an expression was expected of type "b" = "int" 1251 + Error: The value "x" has type "a" = "int" but an expression was expected of type 1252 + "b" = "int" 1253 1253 This instance of "int" is ambiguous: 1254 1254 it would escape the scope of its equation 1255 1255 |}];; ··· 1287 1287 Line 7, characters 35-36: 1288 1288 7 | if true then fun x -> x + 1 else x 1289 1289 ^ 1290 - Error: This expression has type "M.t" = "int -> int" 1290 + Error: The value "x" has type "M.t" = "int -> int" 1291 1291 but an expression was expected of type "int -> int" 1292 1292 This instance of "int -> int" is ambiguous: 1293 1293 it would escape the scope of its equation
+2 -2
testsuite/tests/typing-misc-bugs/pr6303_bad.compilers.reference
··· 1 1 File "pr6303_bad.ml", line 11, characters 22-23: 2 2 11 | let r' : string foo = r 3 3 ^ 4 - Error: This expression has type "int foo" 5 - but an expression was expected of type "string foo" 4 + Error: The value "r" has type "int foo" but an expression was expected of type 5 + "string foo" 6 6 Type "int" is not compatible with type "string"
+102
testsuite/tests/typing-misc/exp_denom.ml
··· 1 + (* TEST 2 + expect; 3 + *) 4 + 5 + (* This test showcases the various denominations used in type clash errors *) 6 + 7 + let f (x : < m : float >) = print_int x#m 8 + 9 + [%%expect {| 10 + Line 1, characters 38-41: 11 + 1 | let f (x : < m : float >) = print_int x#m 12 + ^^^ 13 + Error: The method call "x#m" has type "float" 14 + but an expression was expected of type "int" 15 + |}] 16 + 17 + type r = { f : float } 18 + 19 + let f (x : r) = print_int x.f 20 + 21 + [%%expect {| 22 + type r = { f : float; } 23 + Line 3, characters 26-29: 24 + 3 | let f (x : r) = print_int x.f 25 + ^^^ 26 + Error: The field access "x.f" has type "float" 27 + but an expression was expected of type "int" 28 + |}] 29 + 30 + type v = Cons 31 + 32 + let _ = print_int Cons 33 + 34 + [%%expect {| 35 + type v = Cons 36 + Line 3, characters 18-22: 37 + 3 | let _ = print_int Cons 38 + ^^^^ 39 + Error: The constructor "Cons" has type "v" but an expression was expected of type 40 + "int" 41 + |}] 42 + 43 + let _ = print_int `Cons 44 + 45 + [%%expect {| 46 + Line 1, characters 18-23: 47 + 1 | let _ = print_int `Cons 48 + ^^^^^ 49 + Error: The constructor "`Cons" has type "[> `Cons ]" 50 + but an expression was expected of type "int" 51 + |}] 52 + 53 + let v = 0. 54 + let _ = print_int v 55 + 56 + [%%expect {| 57 + val v : float = 0. 58 + Line 2, characters 18-19: 59 + 2 | let _ = print_int v 60 + ^ 61 + Error: The value "v" has type "float" but an expression was expected of type "int" 62 + |}] 63 + 64 + let _ = print_int 0. 65 + 66 + [%%expect {| 67 + Line 1, characters 18-20: 68 + 1 | let _ = print_int 0. 69 + ^^ 70 + Error: The constant "0." has type "float" but an expression was expected of type 71 + "int" 72 + |}] 73 + 74 + let _ = print_int "foo" 75 + 76 + [%%expect {| 77 + Line 1, characters 18-23: 78 + 1 | let _ = print_int "foo" 79 + ^^^^^ 80 + Error: This constant has type "string" but an expression was expected of type 81 + "int" 82 + |}] 83 + 84 + let _ : int = while false do () done 85 + 86 + [%%expect {| 87 + Line 1, characters 14-36: 88 + 1 | let _ : int = while false do () done 89 + ^^^^^^^^^^^^^^^^^^^^^^ 90 + Error: This "while" expression has type "unit" 91 + but an expression was expected of type "int" 92 + |}] 93 + 94 + let _ : int = for _ = 1 to 2 do () done 95 + 96 + [%%expect {| 97 + Line 1, characters 14-39: 98 + 1 | let _ : int = for _ = 1 to 2 do () done 99 + ^^^^^^^^^^^^^^^^^^^^^^^^^ 100 + Error: This "for" expression has type "unit" 101 + but an expression was expected of type "int" 102 + |}]
+3 -3
testsuite/tests/typing-misc/labels.ml
··· 170 170 Line 1, characters 26-33: 171 171 1 | let () = expect_unlabeled labeled 172 172 ^^^^^^^ 173 - Error: This expression has type "x:'a -> unit" 173 + Error: The value "labeled" has type "x:'a -> unit" 174 174 but an expression was expected of type "unit -> unit" 175 175 The first argument is labeled "x", 176 176 but an unlabeled argument was expected ··· 181 181 Line 1, characters 24-33: 182 182 1 | let () = expect_labeled unlabeled 183 183 ^^^^^^^^^ 184 - Error: This expression has type "'a -> unit" 184 + Error: The value "unlabeled" has type "'a -> unit" 185 185 but an expression was expected of type "x:'b -> unit" 186 186 A label "x" was expected 187 187 |}] ··· 191 191 Line 1, characters 24-35: 192 192 1 | let () = expect_labeled wrong_label 193 193 ^^^^^^^^^^^ 194 - Error: This expression has type "y:'a -> unit" 194 + Error: The value "wrong_label" has type "y:'a -> unit" 195 195 but an expression was expected of type "x:'b -> unit" 196 196 Labels "y" and "x" do not match 197 197 |}]
+1 -1
testsuite/tests/typing-misc/let_rec_approx.ml
··· 17 17 Line 1, characters 17-19: 18 18 1 | let rec f () = g 42 19 19 ^^ 20 - Error: This expression has type "int" but an expression was expected of type 20 + Error: The constant "42" has type "int" but an expression was expected of type 21 21 "string" 22 22 |}] 23 23
+4 -4
testsuite/tests/typing-misc/occur_check.ml
··· 11 11 Line 2, characters 42-43: 12 12 2 | let f (g : 'a list -> 'a t -> 'a) s = g s s;; 13 13 ^ 14 - Error: This expression has type "'a list" 15 - but an expression was expected of type "'a t" = "'a" 14 + Error: The value "s" has type "'a list" but an expression was expected of type 15 + "'a t" = "'a" 16 16 The type variable "'a" occurs inside "'a list" 17 17 |}];; 18 18 ··· 21 21 Line 1, characters 42-43: 22 22 1 | let f (g : 'a * 'b -> 'a t -> 'a) s = g s s;; 23 23 ^ 24 - Error: This expression has type "'a * 'b" 25 - but an expression was expected of type "'a t" = "'a" 24 + Error: The value "s" has type "'a * 'b" but an expression was expected of type 25 + "'a t" = "'a" 26 26 The type variable "'a" occurs inside "'a * 'b" 27 27 |}];; 28 28
+5 -6
testsuite/tests/typing-misc/polyvars.ml
··· 180 180 Line 2, characters 30-31: 181 181 2 | let f: t -> [ `A ] = fun x -> x 182 182 ^ 183 - Error: This expression has type "t" but an expression was expected of type 184 - "[ `A ]" 183 + Error: The value "x" has type "t" but an expression was expected of type "[ `A ]" 185 184 The first variant type is private, it may not allow the tag(s) "`A" 186 185 |}] 187 186 ··· 242 241 Line 5, characters 25-26: 243 242 5 | let f (x:[`X of int]) = (x:[`X]) 244 243 ^ 245 - Error: This expression has type "[ `X of int ]" 244 + Error: The value "x" has type "[ `X of int ]" 246 245 but an expression was expected of type "[ `X ]" 247 246 Types for tag "`X" are incompatible 248 247 |}] ··· 253 252 Line 1, characters 25-26: 254 253 1 | let f (x:[`X of int]) = (x:[<`X of & int]) 255 254 ^ 256 - Error: This expression has type "[ `X of int ]" 255 + Error: The value "x" has type "[ `X of int ]" 257 256 but an expression was expected of type "[< `X of & int ]" 258 257 Types for tag "`X" are incompatible 259 258 |}] ··· 265 264 Line 3, characters 36-37: 266 265 3 | let f (x:[<`X of & int & float]) = (x:[`X]) 267 266 ^ 268 - Error: This expression has type "[< `X of & int & float ]" 267 + Error: The value "x" has type "[< `X of & int & float ]" 269 268 but an expression was expected of type "[ `X ]" 270 269 Types for tag "`X" are incompatible 271 270 |}] ··· 282 281 Line 4, characters 30-31: 283 282 4 | let g (x:[`A | `R of rt]) = f x 284 283 ^ 285 - Error: This expression has type "[ `A | `R of rt ]" 284 + Error: The value "x" has type "[ `A | `R of rt ]" 286 285 but an expression was expected of type "[< `A | `R of 'a ] as 'a" 287 286 Type "rt" = "[ `A | `B of string | `R of rt ]" is not compatible with type 288 287 "[< `A | `R of 'a ] as 'a"
+3 -3
testsuite/tests/typing-misc/pr7103.ml
··· 23 23 Line 1, characters 27-28: 24 24 1 | let _ = fun (x : a t) -> f x;; 25 25 ^ 26 - Error: This expression has type "a t" but an expression was expected of type 26 + Error: The value "x" has type "a t" but an expression was expected of type 27 27 "< .. > t" 28 28 Type "a" is not compatible with type "< .. >" 29 29 |}];; ··· 33 33 Line 1, characters 27-28: 34 34 1 | let _ = fun (x : a t) -> g x;; 35 35 ^ 36 - Error: This expression has type "a t" but an expression was expected of type 36 + Error: The value "x" has type "a t" but an expression was expected of type 37 37 "[< `b ] t" 38 38 Type "a" is not compatible with type "[< `b ]" 39 39 |}];; ··· 43 43 Line 1, characters 27-28: 44 44 1 | let _ = fun (x : a t) -> h x;; 45 45 ^ 46 - Error: This expression has type "a t" but an expression was expected of type 46 + Error: The value "x" has type "a t" but an expression was expected of type 47 47 "[> `b ] t" 48 48 Type "a" is not compatible with type "[> `b ]" 49 49 |}];;
+2 -2
testsuite/tests/typing-misc/pr7937.ml
··· 10 10 Line 3, characters 35-39: 11 11 3 | let f: 'a. 'a r -> 'a r = fun x -> true;; 12 12 ^^^^ 13 - Error: This expression has type "bool" but an expression was expected of type 14 - "([< `X of int & 'a ] as 'a) r" 13 + Error: The constructor "\#true" has type "bool" 14 + but an expression was expected of type "([< `X of int & 'a ] as 'a) r" 15 15 |}] 16 16 17 17 let g: 'a. 'a r -> 'a r = fun x -> { contents = 0 };;
+2 -2
testsuite/tests/typing-misc/printing.ml
··· 79 79 Line 4, characters 32-33: 80 80 4 | | Refl -> if true then x else y 81 81 ^ 82 - Error: This expression has type "a" but an expression was expected of type "t" 82 + Error: The value "y" has type "a" but an expression was expected of type "t" 83 83 This instance of "< m : int * 'a > as 'a" is ambiguous: 84 84 it would escape the scope of its equation 85 85 |}] ··· 94 94 Line 3, characters 22-23: 95 95 3 | let f (x : t1) : t2 = x;; 96 96 ^ 97 - Error: This expression has type "t1" but an expression was expected of type "t2" 97 + Error: The value "x" has type "t1" but an expression was expected of type "t2" 98 98 The method "m" has type "'c. 'c * ('a * < m : 'c. 'b >) as 'b", 99 99 but the expected method type was "'a. 'a * ('a * < m : 'a. 'd >) as 'd" 100 100 The universal variable "'a" would escape its scope
+1 -1
testsuite/tests/typing-misc/scope_escape.ml
··· 9 9 Line 2, characters 34-35: 10 10 2 | module M = struct type t let _ = (x : t list ref) end;; 11 11 ^ 12 - Error: This expression has type "'weak1 list ref" 12 + Error: The value "x" has type "'weak1 list ref" 13 13 but an expression was expected of type "t list ref" 14 14 The type constructor "t" would escape its scope 15 15 |}]
+4 -6
testsuite/tests/typing-misc/unique_names_in_unification.ml
··· 14 14 Line 5, characters 27-28: 15 15 5 | let f: t -> t = fun B -> x 16 16 ^ 17 - Error: This expression has type "t/2" but an expression was expected of type "t" 17 + Error: The value "x" has type "t/2" but an expression was expected of type "t" 18 18 Line 4, characters 2-12: 19 19 Definition of type "t" 20 20 Line 1, characters 0-10: ··· 36 36 Line 7, characters 34-35: 37 37 7 | let f : M.t -> M.t = fun M.C -> y 38 38 ^ 39 - Error: This expression has type "M/2.t" but an expression was expected of type 40 - "M.t" 39 + Error: The value "y" has type "M/2.t" but an expression was expected of type "M.t" 41 40 Lines 4-6, characters 2-5: 42 41 Definition of module "M" 43 42 Line 1, characters 0-32: ··· 53 52 Line 2, characters 25-26: 54 53 2 | let f: t -> t = fun D -> x;; 55 54 ^ 56 - Error: This expression has type "t/2" but an expression was expected of type "t" 55 + Error: The value "x" has type "t/2" but an expression was expected of type "t" 57 56 Line 1, characters 0-10: 58 57 Definition of type "t" 59 58 Line 1, characters 0-10: ··· 76 75 Line 2, characters 32-33: 77 76 2 | let x: ttt = let rec y = A y in y;; 78 77 ^ 79 - Error: This expression has type "ttt/2" but an expression was expected of type 80 - "ttt" 78 + Error: The value "y" has type "ttt/2" but an expression was expected of type "ttt" 81 79 Line 1, characters 0-26: 82 80 Definition of type "ttt" 83 81 Line 2, characters 0-30:
+1 -1
testsuite/tests/typing-missing-cmi-3/user.ml
··· 32 32 Line 1, characters 19-20: 33 33 1 | let () = Middle.(f x) 34 34 ^ 35 - Error: This expression has type "(module Original.T)" 35 + Error: The value "x" has type "(module Original.T)" 36 36 but an expression was expected of type 37 37 "(module Original.T with type t = int)" 38 38 |}]
+1 -2
testsuite/tests/typing-missing-cmi/test.compilers.reference
··· 1 1 File "main.ml", line 1, characters 14-17: 2 2 1 | let _ = A.a = B.b 3 3 ^^^ 4 - Error: This expression has type "M.b" but an expression was expected of type 5 - "M.a" 4 + Error: The value "B.b" has type "M.b" but an expression was expected of type "M.a" 6 5 Type "M.b" is abstract because no corresponding cmi file was found 7 6 in path. 8 7 Type "M.a" is abstract because no corresponding cmi file was found
+1 -1
testsuite/tests/typing-modules-bugs/pr6752_bad.compilers.reference
··· 1 1 File "pr6752_bad.ml", line 26, characters 31-40: 2 2 26 | let q' : Common0.msg Queue.t = Common0.q 3 3 ^^^^^^^^^ 4 - Error: This expression has type "'a Queue.t" 4 + Error: The value "Common0.q" has type "'a Queue.t" 5 5 but an expression was expected of type "Common0.msg Queue.t" 6 6 The type constructor "Common0.msg" would escape its scope
+1 -1
testsuite/tests/typing-modules-bugs/pr6992_bad.compilers.reference
··· 1 1 File "pr6992_bad.ml", line 16, characters 69-71: 2 2 16 | let uniq (type a) (type b) (Eq : a fix) (Eq : b fix) : (a, b) eq = Eq 3 3 ^^ 4 - Error: This expression has type "(a, a) eq" 4 + Error: The constructor "Eq" has type "(a, a) eq" 5 5 but an expression was expected of type "(a, b) eq" 6 6 Type "a" is not compatible with type "b"
+1 -2
testsuite/tests/typing-modules/firstclass.ml
··· 32 32 Line 5, characters 3-4: 33 33 5 | (x : (module S'));; (* fail *) 34 34 ^ 35 - Error: This expression has type 36 - "(module S2 with type t = int and type u = bool)" 35 + Error: The value "x" has type "(module S2 with type t = int and type u = bool)" 37 36 but an expression was expected of type "(module S')" 38 37 Modules do not match: 39 38 S'
+2 -2
testsuite/tests/typing-objects/Exemples.ml
··· 207 207 Line 1, characters 27-28: 208 208 1 | let c'' = new color_circle p;; 209 209 ^ 210 - Error: This expression has type "point" but an expression was expected of type 210 + Error: The value "p" has type "point" but an expression was expected of type 211 211 "#color_point" 212 212 The first object type has no method "color" 213 213 |}];; ··· 588 588 Line 1, characters 25-27: 589 589 1 | (new sorted_list ())#add c3;; 590 590 ^^ 591 - Error: This expression has type 591 + Error: The value "c3" has type 592 592 "int_comparable3" = 593 593 "< cmp : int_comparable -> int; setx : int -> unit; x : int >" 594 594 but an expression was expected of type
+5 -6
testsuite/tests/typing-objects/Tests.ml
··· 416 416 Line 1, characters 30-34: 417 417 1 | class c () = object val x = - true val y = -. () end;; 418 418 ^^^^ 419 - Error: This expression has type "bool" but an expression was expected of type 420 - "int" 419 + Error: The constructor "\#true" has type "bool" 420 + but an expression was expected of type "int" 421 421 |}];; 422 422 423 423 class c () = object method f = 1 method g = 1 method h = 1 end;; ··· 789 789 Line 1, characters 19-20: 790 790 1 | fun (x : 'a t) -> (x : 'a); ();; 791 791 ^ 792 - Error: This expression has type "'a t" but an expression was expected of type 793 - "'a" 792 + Error: The value "x" has type "'a t" but an expression was expected of type "'a" 794 793 The type variable "'a" occurs inside "'a t" 795 794 |}];; 796 795 fun ((x : 'a) | (x : 'a t)) -> ();; ··· 1143 1142 Line 2, characters 54-58: 1144 1143 2 | class c = object (self) method private foo = is_empty self end;; 1145 1144 ^^^^ 1146 - Error: This expression has type "< .. >" but an expression was expected of type 1145 + Error: The value "self" has type "< .. >" but an expression was expected of type 1147 1146 "< >" 1148 1147 Self type cannot be unified with a closed object type 1149 1148 |}];; ··· 1237 1236 Line 1, characters 41-45: 1238 1237 1 | let o = object(self) initializer has_foo self end;; 1239 1238 ^^^^ 1240 - Error: This expression has type "< >" but an expression was expected of type 1239 + Error: The value "self" has type "< >" but an expression was expected of type 1241 1240 "< foo : int; .. >" 1242 1241 The first object type has no method "foo" 1243 1242 |}];;
+2 -2
testsuite/tests/typing-objects/abstract_rows.ml
··· 11 11 Line 4, characters 24-25: 12 12 4 | let f (x:t) (y:u) = x = y;; 13 13 ^ 14 - Error: This expression has type "u" but an expression was expected of type "t" 14 + Error: The value "y" has type "u" but an expression was expected of type "t" 15 15 The second object type has an abstract row, it cannot be closed 16 16 |}] 17 17 ··· 21 21 Line 1, characters 24-25: 22 22 1 | let g (x:u) (y:t) = x = y;; 23 23 ^ 24 - Error: This expression has type "t" but an expression was expected of type "u" 24 + Error: The value "y" has type "t" but an expression was expected of type "u" 25 25 The first object type has an abstract row, it cannot be closed 26 26 |}]
+6 -6
testsuite/tests/typing-objects/dummy.ml
··· 45 45 Line 16, characters 22-26: 46 46 16 | inherit child1' self 47 47 ^^^^ 48 - Error: This expression has type "< child : 'a; previous : 'b option; .. >" 48 + Error: The value "self" has type "< child : 'a; previous : 'b option; .. >" 49 49 but an expression was expected of type "'c" 50 50 Self type cannot escape its class 51 51 |}] ··· 193 193 Line 3, characters 36-41: 194 194 3 | inherit parameter_contains_self param 195 195 ^^^^^ 196 - Error: This expression has type 196 + Error: The value "param" has type 197 197 "< redrawWidget : parameter_contains_self -> unit; .. >" 198 198 but an expression was expected of type 199 199 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >" ··· 209 209 Line 3, characters 26-31: 210 210 3 | parameter_contains_self param;; 211 211 ^^^^^ 212 - Error: This expression has type 212 + Error: The value "param" has type 213 213 "< redrawWidget : parameter_contains_self -> unit; .. >" 214 214 but an expression was expected of type 215 215 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >" ··· 229 229 Line 4, characters 38-43: 230 230 4 | inherit parameter_contains_self param 231 231 ^^^^^ 232 - Error: This expression has type "'a" but an expression was expected of type 232 + Error: The value "param" has type "'a" but an expression was expected of type 233 233 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >" 234 234 Self type cannot escape its class 235 235 |}] ··· 243 243 Line 3, characters 38-43: 244 244 3 | class c = parameter_contains_self param 245 245 ^^^^^ 246 - Error: This expression has type "'a" but an expression was expected of type 246 + Error: The value "param" has type "'a" but an expression was expected of type 247 247 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >" 248 248 Self type cannot escape its class 249 249 |}] ··· 256 256 Line 3, characters 36-41: 257 257 3 | inherit parameter_contains_self param 258 258 ^^^^^ 259 - Error: This expression has type 259 + Error: The value "param" has type 260 260 "< redrawWidget : parameter_contains_self -> unit; .. >" 261 261 but an expression was expected of type 262 262 "< redrawWidget : < invalidate : unit; .. > -> unit; .. >"
+1 -1
testsuite/tests/typing-objects/pr6123_bad.ml
··· 29 29 Line 15, characters 50-54: 30 30 15 | let args = List.map (fun ty -> new argument(self, ty)) args_ty in 31 31 ^^^^ 32 - Error: This expression has type "< arguments : 'a; .. >" 32 + Error: The value "self" has type "< arguments : 'a; .. >" 33 33 but an expression was expected of type "'b" 34 34 Self type cannot escape its class 35 35 |}]
+1 -1
testsuite/tests/typing-objects/self_cannot_be_closed.ml
··· 11 11 Line 1, characters 54-58: 12 12 1 | class c = object (self) method private foo = is_empty self end;; 13 13 ^^^^ 14 - Error: This expression has type "< .. >" but an expression was expected of type 14 + Error: The value "self" has type "< .. >" but an expression was expected of type 15 15 "< >" 16 16 Self type cannot be unified with a closed object type 17 17 |}]
+6 -6
testsuite/tests/typing-poly/error_messages.ml
··· 36 36 Line 4, characters 49-50: 37 37 4 | let f (x:<a:'a; b:'a. 'a>) (y:<a:'a;b:'a>) = x = y 38 38 ^ 39 - Error: This expression has type "< a : 'a; b : 'a >" 39 + Error: The value "y" has type "< a : 'a; b : 'a >" 40 40 but an expression was expected of type "< a : 'a; b : 'a0. 'a0 >" 41 41 The method "b" has type "'a", but the expected method type was "'a0. 'a0" 42 42 The universal variable "'a0" would escape its scope ··· 91 91 Line 1, characters 48-49: 92 92 1 | let f: 'a. ([> `A ] as 'a) -> [ `A ] = fun x -> x 93 93 ^ 94 - Error: This expression has type "[> `A ]" 95 - but an expression was expected of type "[ `A ]" 94 + Error: The value "x" has type "[> `A ]" but an expression was expected of type 95 + "[ `A ]" 96 96 The first variant type is bound to the universal type variable "'a", 97 97 it cannot be closed 98 98 |}] ··· 102 102 Line 1, characters 48-49: 103 103 1 | let f: 'a. [ `A ] -> ([> `A ] as 'a) = fun x -> x 104 104 ^ 105 - Error: This expression has type "[ `A ]" but an expression was expected of type 105 + Error: The value "x" has type "[ `A ]" but an expression was expected of type 106 106 "[> `A ]" 107 107 The second variant type is bound to the universal type variable "'a", 108 108 it cannot be closed ··· 114 114 Line 1, characters 53-54: 115 115 1 | let f: 'a. [ `A | `B ] -> ([> `A ] as 'a) = fun x -> x 116 116 ^ 117 - Error: This expression has type "[ `A | `B ]" 117 + Error: The value "x" has type "[ `A | `B ]" 118 118 but an expression was expected of type "[> `A ]" 119 119 The second variant type is bound to the universal type variable "'a", 120 120 it cannot be closed ··· 126 126 Line 1, characters 59-60: 127 127 1 | let f: 'a. [> `A | `B | `C ] -> ([> `A ] as 'a) = fun x -> x 128 128 ^ 129 - Error: This expression has type "[> `A | `B | `C ]" 129 + Error: The value "x" has type "[> `A | `B | `C ]" 130 130 but an expression was expected of type "[> `A ]" 131 131 The second variant type is bound to the universal type variable "'a", 132 132 it may not allow the tag(s) "`B", "`C"
+10 -11
testsuite/tests/typing-poly/poly.ml
··· 466 466 Line 9, characters 41-42: 467 467 9 | let f (x : < m : 'a. 'a -> 'a list >) = (x : < m : 'b. 'b -> 'c >) 468 468 ^ 469 - Error: This expression has type "< m : 'b. 'b -> 'b list >" 469 + Error: The value "x" has type "< m : 'b. 'b -> 'b list >" 470 470 but an expression was expected of type "< m : 'b. 'b -> 'c >" 471 471 The method "m" has type "'b. 'b -> 'b list", 472 472 but the expected method type was "'b. 'b -> 'c" ··· 590 590 Line 5, characters 24-28: 591 591 5 | let f3 f = f#id 1, f#id true 592 592 ^^^^ 593 - Error: This expression has type "bool" but an expression was expected of type 594 - "int" 593 + Error: The constructor "\#true" has type "bool" 594 + but an expression was expected of type "int" 595 595 |}];; 596 596 597 597 class c = object ··· 1134 1134 Line 2, characters 3-4: 1135 1135 2 | (x : <m : 'a. 'a * (<m:'b. 'a * <m:'c. 'c * 'bar> > as 'bar) >);; 1136 1136 ^ 1137 - Error: This expression has type "< m : 'a. 'a * < m : 'a * 'b > > as 'b" 1137 + Error: The value "x" has type "< m : 'a. 'a * < m : 'a * 'b > > as 'b" 1138 1138 but an expression was expected of type 1139 1139 "< m : 'a. 'a * (< m : 'a * < m : 'c. 'c * 'd > > as 'd) >" 1140 1140 The method "m" has type ··· 1157 1157 Line 2, characters 3-4: 1158 1158 2 | (x : <m : 'b. 'b * ('b * <m : 'c. 'c * ('c * 'bar)>)> as 'bar);; 1159 1159 ^ 1160 - Error: This expression has type 1161 - "< m : 'b. 'b * ('b * < m : 'c. 'c * 'a > as 'a) >" 1160 + Error: The value "x" has type "< m : 'b. 'b * ('b * < m : 'c. 'c * 'a > as 'a) >" 1162 1161 but an expression was expected of type 1163 1162 "< m : 'b. 'b * ('b * < m : 'c. 'c * ('c * 'd) >) > as 'd" 1164 1163 The method "m" has type "'c. 'c * ('b * < m : 'c. 'e >) as 'e", ··· 1399 1398 Line 4, characters 16-22: 1400 1399 4 | let zero = {f = `Int 0} ;; (* fails *) 1401 1400 ^^^^^^ 1402 - Error: This expression has type "[> `Int of int ]" 1401 + Error: This constructor has type "[> `Int of int ]" 1403 1402 but an expression was expected of type "[< `Int of int ]" 1404 1403 The second variant type is bound to the universal type variable "'a", 1405 1404 it may not allow the tag(s) "`Int" ··· 1572 1571 Line 2, characters 3-4: 1573 1572 2 | (n : < m : 'b 'r. [< `Foo of int & 'b | `Bar] as 'r >) 1574 1573 ^ 1575 - Error: This expression has type 1576 - "< m : 'a 'c. [< `Bar | `Foo of 'a & int ] as 'c >" 1574 + Error: The value "n" has type "< m : 'a 'c. [< `Bar | `Foo of 'a & int ] as 'c >" 1577 1575 but an expression was expected of type 1578 1576 "< m : 'b 'd. [< `Bar | `Foo of int & 'b ] as 'd >" 1579 1577 Types for tag "`Foo" are incompatible ··· 1595 1593 Line 3, characters 19-22: 1596 1594 3 | if b then x else M.A;; 1597 1595 ^^^ 1598 - Error: This expression has type "M.t" but an expression was expected of type "'x" 1596 + Error: The constructor "M.A" has type "M.t" 1597 + but an expression was expected of type "'x" 1599 1598 The type constructor "M.t" would escape its scope 1600 1599 |}];; 1601 1600 ··· 1891 1890 Line 1, characters 17-18: 1892 1891 1 | let f (x : u) = (x : v) 1893 1892 ^ 1894 - Error: This expression has type "u" but an expression was expected of type "v" 1893 + Error: The value "x" has type "u" but an expression was expected of type "v" 1895 1894 The method "m" has type "'a s list * < m : 'b > as 'b", 1896 1895 but the expected method type was "'a. 'a s list * < m : 'a. 'c > as 'c" 1897 1896 The universal variable "'a" would escape its scope
+1 -1
testsuite/tests/typing-poly/pr9603.ml
··· 25 25 Line 4, characters 11-12: 26 26 4 | = fun x -> x 27 27 ^ 28 - Error: This expression has type 28 + Error: The value "x" has type 29 29 "< m : 'left 'right. < left : 'left; right : 'right > pair >" 30 30 but an expression was expected of type 31 31 "< m : 'left 'right. < left : 'left; right : 'right > pair >"
+1 -1
testsuite/tests/typing-polyvariants-bugs-2/pr3918c.compilers.reference
··· 1 1 File "pr3918c.ml", line 24, characters 11-12: 2 2 24 | let f x = (x : 'a vlist :> 'b vlist) 3 3 ^ 4 - Error: This expression has type "'b Pr3918b.vlist" 4 + Error: The value "x" has type "'b Pr3918b.vlist" 5 5 but an expression was expected of type "'b Pr3918b.vlist"
+1 -1
testsuite/tests/typing-polyvariants-bugs/pr5057a_bad.compilers.reference
··· 1 1 File "pr5057a_bad.ml", line 14, characters 48-49: 2 2 14 | let _ = match flag with `A -> T.mem | `B r -> r in 3 3 ^ 4 - Error: This expression has type "'a" but an expression was expected of type 4 + Error: The value "r" has type "'a" but an expression was expected of type 5 5 "int -> T.t -> bool" 6 6 The type constructor "T.t" would escape its scope
+2 -3
testsuite/tests/typing-private/private.compilers.principal.reference
··· 3 3 Line 2, characters 20-21: 4 4 2 | let f (x : F0.t) = (x : Foobar.t);; (* fails *) 5 5 ^ 6 - Error: This expression has type "F0.t" but an expression was expected of type 6 + Error: The value "x" has type "F0.t" but an expression was expected of type 7 7 "Foobar.t" 8 8 module F = Foobar 9 9 val f : F.t -> Foobar.t = <fun> ··· 13 13 Line 1, characters 19-20: 14 14 1 | fun (x : M1.t) -> (x : M2.t);; (* fails *) 15 15 ^ 16 - Error: This expression has type "M1.t" but an expression was expected of type 17 - "M2.t" 16 + Error: The value "x" has type "M1.t" but an expression was expected of type "M2.t" 18 17 module M3 : sig type t = private M1.t end 19 18 - : M3.t -> M1.t = <fun> 20 19 - : M3.t -> M.t = <fun>
+2 -3
testsuite/tests/typing-private/private.compilers.reference
··· 3 3 Line 2, characters 20-21: 4 4 2 | let f (x : F0.t) = (x : Foobar.t);; (* fails *) 5 5 ^ 6 - Error: This expression has type "F0.t" but an expression was expected of type 6 + Error: The value "x" has type "F0.t" but an expression was expected of type 7 7 "Foobar.t" 8 8 module F = Foobar 9 9 val f : F.t -> Foobar.t = <fun> ··· 13 13 Line 1, characters 19-20: 14 14 1 | fun (x : M1.t) -> (x : M2.t);; (* fails *) 15 15 ^ 16 - Error: This expression has type "M1.t" but an expression was expected of type 17 - "M2.t" 16 + Error: The value "x" has type "M1.t" but an expression was expected of type "M2.t" 18 17 module M3 : sig type t = private M1.t end 19 18 - : M3.t -> M1.t = <fun> 20 19 - : M3.t -> M.t = <fun>
+1 -1
testsuite/tests/typing-rectypes-bugs/pr6174_bad.compilers.reference
··· 1 1 File "pr6174_bad.ml", line 11, characters 24-25: 2 2 11 | fun C k -> k (fun x -> x);; 3 3 ^ 4 - Error: This expression has type "$0" but an expression was expected of type 4 + Error: The value "x" has type "$0" but an expression was expected of type 5 5 "$1" = "($2 -> $1) -> $1"
+2 -2
testsuite/tests/typing-short-paths/errors.ml
··· 51 51 Line 9, characters 22-23: 52 52 9 | | Pair (Char, x) -> x + 1 53 53 ^ 54 - Error: This expression has type "$a" but an expression was expected of type "int" 54 + Error: The value "x" has type "$a" but an expression was expected of type "int" 55 55 Hint: "$a" is an existential type bound by the constructor "Pair". 56 56 |}] 57 57 ··· 68 68 Line 7, characters 35-36: 69 69 7 | | Pair (Char, x) -> if true then x else 'd' 70 70 ^ 71 - Error: This expression has type "$a" but an expression was expected of type "'a" 71 + Error: The value "x" has type "$a" but an expression was expected of type "'a" 72 72 This instance of "$a" is ambiguous: 73 73 it would escape the scope of its equation 74 74 Hint: "$a" is an existential type bound by the constructor "Pair".
+1 -1
testsuite/tests/typing-short-paths/short-paths.compilers.reference
··· 69 69 Line 1, characters 8-9: 70 70 1 | let y = x + x ;; 71 71 ^ 72 - Error: This expression has type "'a Int.Map.t" 72 + Error: The value "x" has type "'a Int.Map.t" 73 73 but an expression was expected of type "int" 74 74 module M : sig type t = A type u = C end 75 75 module N : sig type t = B end
+2 -2
testsuite/tests/typing-typeparam/newtype.ocaml.reference
··· 8 8 Line 2, characters 32-33: 9 9 2 | let f x (type a) (y : a) = (x = y);; (* Fails *) 10 10 ^ 11 - Error: This expression has type "a" but an expression was expected of type "'a" 11 + Error: The value "y" has type "a" but an expression was expected of type "'a" 12 12 The type constructor "a" would escape its scope 13 13 Line 3, characters 53-54: 14 14 3 | method n : 'a -> 'a = fun (type g) (x:g) -> self#m x 15 15 ^ 16 - Error: This expression has type "g" but an expression was expected of type "'a" 16 + Error: The value "x" has type "g" but an expression was expected of type "'a" 17 17 The type constructor "g" would escape its scope 18 18
+1 -2
testsuite/tests/typing-warnings/records.ml
··· 106 106 Line 3, characters 35-36: 107 107 3 | let f r = match r with {x; y} -> y + y 108 108 ^ 109 - Error: This expression has type "bool" but an expression was expected of type 110 - "int" 109 + Error: The value "y" has type "bool" but an expression was expected of type "int" 111 110 |}] 112 111 113 112 module F2 = struct
+80 -43
typing/typecore.ml
··· 111 111 | Orpat_vars of Ident.t * Ident.t list 112 112 | Expr_type_clash of 113 113 Errortrace.unification_error * type_forcing_context option 114 - * Parsetree.expression_desc option 114 + * Parsetree.expression option 115 115 | Function_arity_type_clash of 116 116 { syntactic_arity : int; 117 117 type_constraint : type_expr; ··· 3161 3161 3162 3162 (* Typing of expressions *) 3163 3163 3164 - (** [sdesc_for_hint] is used by error messages to report literals in their 3164 + (** [sexp_for_hint] is used by error messages to report literals in their 3165 3165 original formatting *) 3166 - let unify_exp ?sdesc_for_hint env exp expected_ty = 3166 + let unify_exp ~sexp env exp expected_ty = 3167 3167 let loc = proper_exp_loc exp in 3168 3168 try 3169 3169 unify_exp_types loc env exp.exp_type expected_ty 3170 3170 with Error(loc, env, Expr_type_clash(err, tfc, None)) -> 3171 - raise (Error(loc, env, Expr_type_clash(err, tfc, sdesc_for_hint))) 3171 + raise (Error(loc, env, Expr_type_clash(err, tfc, Some sexp))) 3172 3172 3173 3173 (* If [is_inferred e] is true, [e] will be typechecked without using 3174 3174 the "expected type" provided by the context. *) ··· 3313 3313 env sexp ty_expected_explained = 3314 3314 let { ty = ty_expected; explanation } = ty_expected_explained in 3315 3315 let loc = sexp.pexp_loc in 3316 - let desc = sexp.pexp_desc in 3317 3316 (* Record the expression type before unifying it with the expected type *) 3318 3317 let with_explanation = with_explanation explanation in 3319 3318 (* Unify the result with [ty_expected], enforcing the current level *) 3320 3319 let rue exp = 3321 3320 with_explanation (fun () -> 3322 - unify_exp ~sdesc_for_hint:desc env (re exp) (instance ty_expected)); 3321 + unify_exp ~sexp env (re exp) (instance ty_expected)); 3323 3322 exp 3324 3323 in 3325 - match desc with 3324 + match sexp.pexp_desc with 3326 3325 | Pexp_ident lid -> 3327 3326 let path, desc = type_ident env ~recarg lid in 3328 3327 let exp_desc = ··· 3455 3454 end 3456 3455 ~before_generalize:(fun (_pat_exp_list, body, new_env) -> 3457 3456 (* The "body" component of the scope escape check. *) 3458 - unify_exp new_env body (newvar ())) 3457 + unify_exp ~sexp new_env body (newvar ())) 3459 3458 in 3460 3459 re { 3461 3460 exp_desc = Texp_let(rec_flag, pat_exp_list, body); ··· 3653 3652 exp_attributes = sexp.pexp_attributes; 3654 3653 exp_env = env } 3655 3654 | Pexp_construct(lid, sarg) -> 3656 - type_construct env loc lid sarg ty_expected_explained sexp.pexp_attributes 3655 + type_construct env ~sexp lid sarg ty_expected_explained 3657 3656 | Pexp_variant(l, sarg) -> 3658 3657 (* Keep sharing *) 3659 3658 let ty_expected1 = protect_expansion env ty_expected in ··· 3842 3841 type_label_access env srecord Env.Projection lid 3843 3842 in 3844 3843 let (_, ty_arg, ty_res) = instance_label ~fixed:false label in 3845 - unify_exp env record ty_res; 3844 + unify_exp ~sexp env record ty_res; 3846 3845 rue { 3847 3846 exp_desc = Texp_field(record, lid, label); 3848 3847 exp_loc = loc; exp_extra = []; ··· 3856 3855 if expected_type = None then newvar () else record.exp_type in 3857 3856 let (label_loc, label, newval) = 3858 3857 type_label_exp false env loc ty_record (lid, label, snewval) in 3859 - unify_exp env record ty_record; 3858 + unify_exp ~sexp env record ty_record; 3860 3859 if label.lbl_mut = Immutable then 3861 3860 raise(Error(loc, env, Label_not_mutable lid.txt)); 3862 3861 rue { ··· 3895 3894 let ifso = type_expect env sifso ty_expected_explained in 3896 3895 let ifnot = type_expect env sifnot ty_expected_explained in 3897 3896 (* Keep sharing *) 3898 - unify_exp env ifnot ifso.exp_type; 3897 + unify_exp ~sexp env ifnot ifso.exp_type; 3899 3898 re { 3900 3899 exp_desc = Texp_ifthenelse(cond, ifso, Some ifnot); 3901 3900 exp_loc = loc; exp_extra = []; ··· 4228 4227 | Tvar _ -> 4229 4228 let exp = type_exp env sbody in 4230 4229 let exp = {exp with exp_type = newty (Tpoly (exp.exp_type, []))} in 4231 - unify_exp env exp ty; 4230 + unify_exp ~sexp env exp ty; 4232 4231 exp 4233 4232 | _ -> assert false 4234 4233 in ··· 5207 5206 let args, ty_fun', simple_res = make_args [] texp.exp_type 5208 5207 and texp = {texp with exp_type = instance texp.exp_type} in 5209 5208 if not (simple_res || safe_expect) then begin 5210 - unify_exp env texp ty_expected; 5209 + unify_exp ~sexp:sarg env texp ty_expected; 5211 5210 texp 5212 5211 end else begin 5213 5212 let warn = !Clflags.principal && ··· 5218 5217 Tarrow(Nolabel,ty_arg,ty_res,_) -> ty_arg, ty_res 5219 5218 | _ -> assert false 5220 5219 in 5221 - unify_exp env {texp with exp_type = ty_fun} ty_expected; 5220 + unify_exp ~sexp:sarg env {texp with exp_type = ty_fun} ty_expected; 5222 5221 if args = [] then texp else 5223 5222 (* eta-expand to avoid side effects *) 5224 5223 let var_pair name ty = ··· 5278 5277 | None -> 5279 5278 let texp = type_expect ?recarg env sarg 5280 5279 (mk_expected ?explanation ty_expected') in 5281 - unify_exp env texp ty_expected; 5280 + unify_exp ~sexp:sarg env texp ty_expected; 5282 5281 texp 5283 5282 5284 5283 and type_application env funct sargs = ··· 5343 5342 let arg () = 5344 5343 let arg = type_expect env sarg (mk_expected ty_arg) in 5345 5344 if is_optional lbl then 5346 - unify_exp env arg (type_option(newvar())); 5345 + unify_exp ~sexp:sarg env arg (type_option(newvar())); 5347 5346 arg 5348 5347 in 5349 5348 (ty_res, (lbl, Some (arg, Some sarg.pexp_loc)) :: typed_args) ··· 5486 5485 let ty = funct.exp_type in 5487 5486 type_args [] ty (instance ty) sargs 5488 5487 5489 - and type_construct env loc lid sarg ty_expected_explained attrs = 5488 + and type_construct env ~sexp lid sarg ty_expected_explained = 5490 5489 let { ty = ty_expected; explanation } = ty_expected_explained in 5491 5490 let expected_type = 5492 5491 match extract_concrete_variant env ty_expected with ··· 5497 5496 let srt = wrong_kind_sort_of_constructor lid.txt in 5498 5497 let ctx = Expression explanation in 5499 5498 let error = Wrong_expected_kind(srt, ctx, ty_expected) in 5500 - raise (Error (loc, env, error)) 5499 + raise (Error (sexp.pexp_loc, env, error)) 5501 5500 in 5502 5501 let constrs = 5503 5502 Env.lookup_all_constructors ~loc:lid.loc Env.Positive lid.txt env ··· 5511 5510 match sarg with 5512 5511 None -> [] 5513 5512 | Some {pexp_desc = Pexp_tuple sel} when 5514 - constr.cstr_arity > 1 || Builtin_attributes.explicit_arity attrs 5513 + constr.cstr_arity > 1 5514 + || Builtin_attributes.explicit_arity sexp.pexp_attributes 5515 5515 -> sel 5516 5516 | Some se -> [se] in 5517 5517 if List.length sargs <> constr.cstr_arity then 5518 - raise(Error(loc, env, Constructor_arity_mismatch 5519 - (lid.txt, constr.cstr_arity, List.length sargs))); 5518 + raise(Error(sexp.pexp_loc, env, 5519 + Constructor_arity_mismatch 5520 + (lid.txt, constr.cstr_arity, List.length sargs))); 5520 5521 let separate = !Clflags.principal || Env.has_local_constraints env in 5521 5522 let ty_args, ty_res, texp = 5522 5523 with_local_level_generalize_structure_if separate begin fun () -> ··· 5528 5529 let texp = 5529 5530 re { 5530 5531 exp_desc = Texp_construct(lid, constr, []); 5531 - exp_loc = loc; exp_extra = []; 5532 + exp_loc = sexp.pexp_loc; exp_extra = []; 5532 5533 exp_type = ty_res; 5533 - exp_attributes = attrs; 5534 + exp_attributes = sexp.pexp_attributes; 5534 5535 exp_env = env } in 5535 5536 (ty_args, ty_res, texp) 5536 5537 end 5537 5538 in 5538 5539 with_explanation explanation (fun () -> 5539 - unify_exp env {texp with exp_type = instance ty_res} 5540 + unify_exp ~sexp env {texp with exp_type = instance ty_res} 5540 5541 (instance ty_expected)); 5541 5542 (ty_args, ty_res, texp) 5542 5543 end ··· 5547 5548 | _ -> assert false 5548 5549 in 5549 5550 let texp = {texp with exp_type = ty_res} in 5550 - if not separate then unify_exp env texp (instance ty_expected); 5551 + if not separate then unify_exp ~sexp env texp (instance ty_expected); 5551 5552 let recarg = 5552 5553 match constr.cstr_inlined with 5553 5554 | None -> Rejected ··· 5558 5559 Pexp_record (_, (Some {pexp_desc = Pexp_ident _}| None))}] -> 5559 5560 Required 5560 5561 | _ -> 5561 - raise (Error(loc, env, Inlined_record_expected)) 5562 + raise (Error(sexp.pexp_loc, env, Inlined_record_expected)) 5562 5563 end 5563 5564 in 5564 5565 let args = ··· 5567 5568 if constr.cstr_private = Private then 5568 5569 begin match constr.cstr_tag with 5569 5570 | Cstr_extension _ -> 5570 - raise(Error(loc, env, Private_constructor (constr, ty_res))) 5571 + raise(Error(sexp.pexp_loc, env, Private_constructor (constr, ty_res))) 5571 5572 | Cstr_constant _ | Cstr_block _ | Cstr_unboxed -> 5572 - raise (Error(loc, env, Private_type ty_res)); 5573 + raise (Error(sexp.pexp_loc, env, Private_type ty_res)); 5573 5574 end; 5574 5575 (* NOTE: shouldn't we call "re" on this final expression? -- AF *) 5575 5576 { texp with ··· 5606 5607 if !Clflags.strict_sequence then 5607 5608 let expected_ty = instance Predef.type_unit in 5608 5609 with_explanation explanation (fun () -> 5609 - unify_exp env exp expected_ty) 5610 + unify_exp ~sexp env exp expected_ty) 5610 5611 else begin 5611 5612 check_partial_application ~statement:true exp; 5612 5613 enforce_current_level env ty ··· 6421 6422 | _ -> None 6422 6423 )) 6423 6424 6425 + (** More precise denomination for type errors. Used by messages: 6426 + 6427 + - [This <denom> ...] 6428 + - [The <denom> "foo" ...] *) 6429 + let pp_exp_denom ppf pexp = 6430 + let d = pp_print_string ppf in 6431 + let d_expression = fprintf ppf "%a expression" Style.inline_code in 6432 + match pexp.pexp_desc with 6433 + | Pexp_constant _ -> d "constant" 6434 + | Pexp_ident _ -> d "value" 6435 + | Pexp_construct _ | Pexp_variant _ -> d "constructor" 6436 + | Pexp_field _ -> d "field access" 6437 + | Pexp_send _ -> d "method call" 6438 + | Pexp_while _ -> d_expression "while" 6439 + | Pexp_for _ -> d_expression "for" 6440 + | Pexp_ifthenelse _ -> d_expression "if-then-else" 6441 + | Pexp_match _ -> d_expression "match" 6442 + | Pexp_try _ -> d_expression "try-with" 6443 + | _ -> d "expression" 6444 + 6445 + (** Implements the "This expression" message, printing the expression if it 6446 + should be according to {!Parsetree.Doc.nominal_exp}. *) 6447 + let report_this_pexp_has_type denom ppf exp = 6448 + let denom ppf = 6449 + match denom, exp with 6450 + | Some d, _ -> fprintf ppf "%s" d 6451 + | None, Some exp -> pp_exp_denom ppf exp 6452 + | None, None -> fprintf ppf "expression" 6453 + in 6454 + let nexp = Option.bind exp Pprintast.Doc.nominal_exp in 6455 + match nexp with 6456 + | Some nexp -> 6457 + fprintf ppf "The %t %a has type" denom (Style.as_inline_code pp_doc) nexp 6458 + | _ -> fprintf ppf "This %t has type" denom 6459 + 6460 + let report_this_texp_has_type denom ppf texp = 6461 + report_this_pexp_has_type denom ppf (Some (Untypeast.untype_expression texp)) 6462 + 6424 6463 (* Hint on type error on integer literals 6425 6464 To avoid confusion, it is disabled on float literals 6426 6465 and when the expected type is `int` *) ··· 6471 6510 6472 6511 let report_expr_type_clash_hints exp diff = 6473 6512 match exp with 6474 - | Some (Pexp_constant const) -> report_literal_type_constraint const diff 6475 - | Some (Pexp_apply _) -> report_partial_application diff 6476 - | _ -> [] 6513 + | Some exp -> begin 6514 + match exp.pexp_desc with 6515 + | Pexp_constant const -> report_literal_type_constraint const diff 6516 + | Pexp_apply _ -> report_partial_application diff 6517 + | _ -> [] 6518 + end 6519 + | None -> [] 6477 6520 6478 6521 let report_pattern_type_clash_hints pat diff = 6479 6522 match pat with ··· 6515 6558 Printtyp.report_unification_error ppf env err 6516 6559 ?type_expected_explanation txt1 txt2 6517 6560 ) () 6518 - 6519 - let report_this_function ppf funct = 6520 - match Typedtree.nominal_exp_doc Printtyp.longident funct with 6521 - | None -> Fmt.fprintf ppf "This function" 6522 - | Some name -> 6523 - Fmt.fprintf ppf "The function %a" 6524 - (Style.as_inline_code Fmt.pp_doc) name 6525 6561 6526 6562 let report_too_many_arg_error ~funct ~func_ty ~previous_arg_loc 6527 6563 ~extra_arg_loc ~returns_unit loc = ··· 6549 6585 msg ~loc:extra_arg_loc "This extra argument is not expected."; 6550 6586 ] in 6551 6587 errorf ~loc:app_loc ~sub 6552 - "@[<v>@[<2>%a has type@ %a@]\ 6588 + "@[<v>@[<2>%a@ %a@]\ 6553 6589 @ It is applied to too many arguments@]" 6554 - report_this_function funct Printtyp.type_expr func_ty 6590 + (report_this_texp_has_type (Some "function")) funct 6591 + Printtyp.type_expr func_ty 6555 6592 6556 6593 let msg = Fmt.doc_printf 6557 6594 ··· 6596 6633 report_unification_error ~loc ~sub env err 6597 6634 ~type_expected_explanation: 6598 6635 (report_type_expected_explanation_opt explanation) 6599 - (msg "This expression has type") 6636 + (msg "%a" (report_this_pexp_has_type None) exp) 6600 6637 (msg "but an expression was expected of type"); 6601 6638 | Function_arity_type_clash { 6602 6639 syntactic_arity; type_constraint; trace = { trace };
+1 -1
typing/typecore.mli
··· 163 163 | Orpat_vars of Ident.t * Ident.t list 164 164 | Expr_type_clash of 165 165 Errortrace.unification_error * type_forcing_context option 166 - * Parsetree.expression_desc option 166 + * Parsetree.expression option 167 167 | Function_arity_type_clash of 168 168 { syntactic_arity : int; 169 169 type_constraint : type_expr;
-35
typing/typedtree.ml
··· 893 893 combine_opts (into cpat) exns1 exns2 894 894 in 895 895 split_pattern pat 896 - 897 - (* Expressions are considered nominal if they can be used as the subject of a 898 - sentence or action. In practice, we consider that an expression is nominal 899 - if they satisfy one of: 900 - - Similar to an identifier: words separated by '.' or '#'. 901 - - Do not contain spaces when printed. 902 - *) 903 - let nominal_exp_doc lid t = 904 - let open Format_doc.Doc in 905 - let longident l = Format_doc.doc_printer lid l.Location.txt in 906 - let rec nominal_exp_doc doc exp = 907 - match exp.exp_desc with 908 - | _ when exp.exp_attributes <> [] -> None 909 - | Texp_ident (_,l,_) -> 910 - Some (longident l doc) 911 - | Texp_instvar (_,_,s) -> 912 - Some (string s.Location.txt doc) 913 - | Texp_constant _ -> assert false 914 - | Texp_variant (lbl, None) -> 915 - Some (printf "`%s" lbl doc) 916 - | Texp_construct (l, _, []) -> Some (longident l doc) 917 - | Texp_field (parent, lbl, _) -> 918 - Option.map 919 - (printf ".%t" (longident lbl)) 920 - (nominal_exp_doc doc parent) 921 - | Texp_send (parent, meth) -> 922 - let name = match meth with 923 - | Tmeth_name name -> name 924 - | Tmeth_val id | Tmeth_ancestor (id,_) -> Ident.name id in 925 - Option.map 926 - (printf "#%s" name) 927 - (nominal_exp_doc doc parent) 928 - | _ -> None 929 - in 930 - nominal_exp_doc empty t
-6
typing/typedtree.mli
··· 919 919 (** Splits an or pattern into its value (left) and exception (right) parts. *) 920 920 val split_pattern: 921 921 computation general_pattern -> pattern option * pattern option 922 - 923 - (** Returns a format document if the expression reads nicely as the subject of a 924 - sentence in a error message. *) 925 - val nominal_exp_doc : 926 - Longident.t Format_doc.printer -> expression 927 - -> Format_doc.t option