-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A type for unification traces #2047
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(* TEST | ||
* expect | ||
*) | ||
|
||
class virtual t = object method virtual x: float end | ||
|
||
class x = object(self: <x:int; ..>) | ||
inherit t | ||
end | ||
[%%expect {| | ||
class virtual t : object method virtual x : float end | ||
Line 4, characters 16-17: | ||
inherit t | ||
^ | ||
Error: The method x has type int but is expected to have type float | ||
Type int is not compatible with type float | ||
|}] | ||
|
||
let x = | ||
let module M = struct module type t = sig end end in | ||
(module struct end: M.t) | ||
[%%expect {| | ||
Line 3, characters 2-26: | ||
(module struct end: M.t) | ||
^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: This expression has type (module M.t) | ||
but an expression was expected of type 'a | ||
The module type M.t would escape its scope | ||
|}] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
constraints.ml | ||
disambiguate_principality.ml | ||
exotic_unifications.ml | ||
inside_out.ml | ||
labels.ml | ||
occur_check.ml | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(* TEST | ||
* expect | ||
*) | ||
type u = <x:int> | ||
type t = private <u; ..> | ||
|
||
let f (x:t) (y:u) = x = y;; | ||
[%%expect{| | ||
type u = < x : int > | ||
type t = private < x : int; .. > | ||
Line 4, characters 24-25: | ||
let f (x:t) (y:u) = x = y;; | ||
^ | ||
Error: This expression has type u but an expression was expected of type t | ||
The second object type has an abstract row, it cannot be closed | ||
|}] | ||
|
||
|
||
let g (x:u) (y:t) = x = y;; | ||
[%%expect{| | ||
Line 1, characters 24-25: | ||
let g (x:u) (y:t) = x = y;; | ||
^ | ||
Error: This expression has type t but an expression was expected of type u | ||
The first object type has an abstract row, it cannot be closed | ||
|}] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
abstract_rows.ml | ||
dummy.ml | ||
errors.ml | ||
Exemples.ml | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ Error: This expression has type | |
refer1 = < poly : 'a 'b 'c. ('b, 'c) #Classdef.cl2 as 'a > | ||
but an expression was expected of type | ||
refer2 = < poly : 'd 'b 'c. ('b, 'c) #Classdef.cl2 as 'd > | ||
Type | ||
('b, 'c) Classdef.cl1 = | ||
< m : 'b -> 'c -> int; raise_trouble : int -> 'b > | ||
Type ('b, 'c, ('b, 'c) Classdef.cl1) Classdef.cl0 = < > | ||
is not compatible with type | ||
< m : 'b -> 'c -> int; raise_trouble : int -> 'b > | ||
The type variable 'e occurs inside 'e | ||
('b0, 'c0, ('b0, 'c0) Classdef.cl1) Classdef.cl0 | ||
Type < m : 'b -> 'c -> int; .. > is not compatible with type | ||
('b, 'c) Classdef.cl1 = | ||
< m : 'b -> 'c -> int; raise_trouble : int -> 'b > | ||
The universal variable 'b would escape its scope | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, it is very hard to make sense of this error message ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It helps to refer to the mantis ticket, which explains that this is a problem with the escape check for universal type variable. In other words, the error is wrong, but at least the error message now points to the source of the problem. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1098,7 +1098,7 @@ Line 2, characters 3-4: | |
Error: This expression has type < m : 'a. 'a * < m : 'a * 'b > > as 'b | ||
but an expression was expected of type | ||
< m : 'a. 'a * (< m : 'a * < m : 'c. 'c * 'd > > as 'd) > | ||
Types for method m are incompatible | ||
The universal variable 'a would escape its scope | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we maybe have an The error message doesn't make much sense (before or after the change) to a human reader, but I understand why this is an error: if you unfold the recursive |
||
|}];; | ||
|
||
fun (x : <m : 'a. 'a * ('a * <m : 'a. 'a * 'foo> as 'foo)>) -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
File "pr3918c.ml", line 24, characters 11-12: | ||
Error: This expression has type 'b Pr3918b.vlist = 'a | ||
but an expression was expected of type 'b Pr3918b.vlist | ||
The type variable 'a occurs inside 'a | ||
The type variable 'a occurs inside ('d * 'c) Pr3918a.voption as 'c | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Again an expect-style test would help here.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the error messages here fairly hard to review. Before the patch, the message is very strange (it starts by saying that two visually identical types are incompatibe). After the patch, some of the strageness is removed, but the error message remains unreadable and incomprehensible. I guess this is unavoidable (without substantially more work) and I am not suggesting/requesting any additional improvement to the error-message logic, but maybe this could be converted to an expect-test, to at least make the test cases more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This original error message here is indeed extremely confusing because it lost track of which types were the actual and the expected due to a double expansion of the trace. In the first two suberrors, the error messages is in fact comparing the actual type with itself then the expected type with itself.