summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Angeletti <octa@polychoron.fr>2018-08-17 22:48:47 +0200
committerFlorian Angeletti <octa@polychoron.fr>2018-08-22 12:30:58 +0200
commit1e9d264727caa39069ae2576b350fab76b37bbf9 (patch)
tree90255ecef5a2260bb312c566ed17a08b4ddc8973
parentf6a9f0e9f75d12a7e88059628bf76421d39b7928 (diff)
downloadocaml-1e9d264727caa39069ae2576b350fab76b37bbf9.tar.gz
contextualization for unbound type variable error
-rw-r--r--testsuite/tests/typing-misc/ocamltests1
-rw-r--r--testsuite/tests/typing-misc/typetexp_errors.ml13
-rw-r--r--typing/typetexp.ml15
-rw-r--r--typing/typetexp.mli1
4 files changed, 19 insertions, 11 deletions
diff --git a/testsuite/tests/typing-misc/ocamltests b/testsuite/tests/typing-misc/ocamltests
index 8af4d8e799..be8fde57c8 100644
--- a/testsuite/tests/typing-misc/ocamltests
+++ b/testsuite/tests/typing-misc/ocamltests
@@ -22,3 +22,4 @@ empty_variant.ml
typecore_errors.ml
typecore_nolabel_errors.ml
typecore_empty_polyvariant_error.ml
+typetexp_errors.ml \ No newline at end of file
diff --git a/testsuite/tests/typing-misc/typetexp_errors.ml b/testsuite/tests/typing-misc/typetexp_errors.ml
new file mode 100644
index 0000000000..c430d794d4
--- /dev/null
+++ b/testsuite/tests/typing-misc/typetexp_errors.ml
@@ -0,0 +1,13 @@
+(* TEST
+ * expect
+*)
+
+type ('a,'at,'any,'en) t = A of 'an
+[%%expect {|
+Line 1, characters 32-35:
+ type ('a,'at,'any,'en) t = A of 'an
+ ^^^
+Error: The type variable 'an is unbound in this type declaration.
+Hint: Did you mean 'a, 'any, 'at or 'en?
+|}
+]
diff --git a/typing/typetexp.ml b/typing/typetexp.ml
index 43440b039e..9e03a3fb82 100644
--- a/typing/typetexp.ml
+++ b/typing/typetexp.ml
@@ -279,12 +279,6 @@ let new_global_var ?name () =
let newvar ?name () =
newvar ?name:(validate_name name) ()
-let type_variable loc name =
- try
- TyVarMap.find name !type_variables
- with Not_found ->
- raise(Error(loc, Env.empty, Unbound_type_variable ("'" ^ name)))
-
let transl_type_param env styp =
let loc = styp.ptyp_loc in
match styp.ptyp_desc with
@@ -887,10 +881,11 @@ let fold_cltypes = fold_simple Env.fold_cltypes
let report_error env ppf = function
| Unbound_type_variable name ->
- (* we don't use "spellcheck" here: the function that raises this
- error seems not to be called anywhere, so it's unclear how it
- should be handled *)
- fprintf ppf "Unbound type parameter %s@." name
+ let add_name name _ l = if name = "_" then l else ("'" ^ name) :: l in
+ let names = TyVarMap.fold add_name !type_variables [] in
+ fprintf ppf "The type variable %s is unbound in this type declaration.@ %a"
+ name
+ did_you_mean (fun () -> Misc.spellcheck names name )
| Unbound_type_constructor lid ->
fprintf ppf "Unbound type constructor %a" longident lid;
spellcheck ppf fold_types env lid;
diff --git a/typing/typetexp.mli b/typing/typetexp.mli
index c4945448ae..7177527903 100644
--- a/typing/typetexp.mli
+++ b/typing/typetexp.mli
@@ -28,7 +28,6 @@ val transl_simple_type_delayed:
val transl_type_scheme:
Env.t -> Parsetree.core_type -> Typedtree.core_type
val reset_type_variables: unit -> unit
-val type_variable: Location.t -> string -> type_expr
val transl_type_param:
Env.t -> Parsetree.core_type -> Typedtree.core_type