summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Angeletti <octa@polychoron.fr>2018-08-20 21:08:43 +0200
committerGitHub <noreply@github.com>2018-08-20 21:08:43 +0200
commitb026bda878792de5cc2efc84c88608bc4125ae20 (patch)
tree82b76eeb581c1304046fcbf2b4f9bef21e0c8b7a
parent4d3088cdbe5ceea0fd03bb29c3d4856e8ed995d8 (diff)
downloadocaml-b026bda878792de5cc2efc84c88608bc4125ae20.tar.gz
Expanded error message for universal quantification failure (#1993)
-rw-r--r--Changes3
-rw-r--r--testsuite/tests/typing-poly/error_messages.ml28
-rw-r--r--testsuite/tests/typing-poly/ocamltests1
-rw-r--r--typing/typetexp.ml14
4 files changed, 41 insertions, 5 deletions
diff --git a/Changes b/Changes
index 03c1632a56..36416cbc8e 100644
--- a/Changes
+++ b/Changes
@@ -170,6 +170,9 @@ Working version
* GPR#1979: Remove support for TERM=norepeat when displaying errors
(Armaël Guéneau, review by Gabriel Scherer and Florian Angeletti)
+- GPR#1993: Expanded error messages for universal quantification failure
+ (Florian Angeletti, review by Jacques Garrigue)
+
### Code generation and optimizations:
- MPR#7725, GPR#1754: improve AFL instrumentation for objects and lazy values.
diff --git a/testsuite/tests/typing-poly/error_messages.ml b/testsuite/tests/typing-poly/error_messages.ml
new file mode 100644
index 0000000000..195e5c2700
--- /dev/null
+++ b/testsuite/tests/typing-poly/error_messages.ml
@@ -0,0 +1,28 @@
+(* TEST
+ * expect
+*)
+
+type t = < x : 'a. int as 'a >
+[%%expect {|
+Line 1, characters 15-28:
+ type t = < x : 'a. int as 'a >
+ ^^^^^^^^^^^^^
+Error: The universal type variable 'a cannot be generalized: it is bound to
+ int.
+|}]
+type u = < x : 'a 'b. 'a as 'b >
+[%%expect {|
+Line 1, characters 15-30:
+ type u = < x : 'a 'b. 'a as 'b >
+ ^^^^^^^^^^^^^^^
+Error: The universal type variable 'b cannot be generalized:
+ it is already bound to another variable.
+|}]
+type v = 'b -> < x : 'a. 'b as 'a >
+[%%expect {|
+Line 1, characters 21-33:
+ type v = 'b -> < x : 'a. 'b as 'a >
+ ^^^^^^^^^^^^
+Error: The universal type variable 'a cannot be generalized:
+ it escapes its scope.
+|}]
diff --git a/testsuite/tests/typing-poly/ocamltests b/testsuite/tests/typing-poly/ocamltests
index be3e71104b..050266c64d 100644
--- a/testsuite/tests/typing-poly/ocamltests
+++ b/testsuite/tests/typing-poly/ocamltests
@@ -1 +1,2 @@
+error_messages.ml
poly.ml
diff --git a/typing/typetexp.ml b/typing/typetexp.ml
index 41ffb10dd8..43440b039e 100644
--- a/typing/typetexp.ml
+++ b/typing/typetexp.ml
@@ -953,11 +953,15 @@ let report_error env ppf = function
fprintf ppf "The type variable name %s is not allowed in programs" name
| Cannot_quantify (name, v) ->
fprintf ppf
- "@[<hov>The universal type variable '%s cannot be generalized:@ %s.@]"
- name
- (if Btype.is_Tvar v then "it escapes its scope" else
- if Btype.is_Tunivar v then "it is already bound to another variable"
- else "it is not a variable")
+ "@[<hov>The universal type variable '%s cannot be generalized:@ "
+ name;
+ if Btype.is_Tvar v then
+ fprintf ppf "it escapes its scope"
+ else if Btype.is_Tunivar v then
+ fprintf ppf "it is already bound to another variable"
+ else
+ fprintf ppf "it is bound to@ %a" Printtyp.type_expr v;
+ fprintf ppf ".@]";
| Multiple_constraints_on_type s ->
fprintf ppf "Multiple constraints for type %a" longident s
| Method_mismatch (l, ty, ty') ->