Navigation Menu

Skip to content
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

Make tuple expression type errors more specific #5347

Closed
vicuna opened this issue Aug 24, 2011 · 2 comments
Closed

Make tuple expression type errors more specific #5347

vicuna opened this issue Aug 24, 2011 · 2 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Aug 24, 2011

Original bug ID: 5347
Reporter: bartjacobs
Assigned to: @garrigue
Status: closed (set by @garrigue on 2012-06-01T07:10:08Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.12.1
Fixed in version: 3.13.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: bartjacobs "Pascal Cuoq"

Bug description

Currently, the error message generated by OCaml in case of an ill-typed tuple expression is less specific than the error message generated in case of an analogous ill-typed variant expression. For example:

let x: int * int = 1, "Hello";;

Characters 19-29:
let x: int * int = 1, "Hello";;
^^^^^^^^^^
Error: This expression has type int * string
but an expression was expected of type int * int

type ('a, 'b) pair = Pair of 'a * 'b;;

type ('a, 'b) pair = Pair of 'a * 'b

let x: (int, int) pair = Pair (1, "Hello");;

Characters 34-41:
let x: (int, int) pair = Pair (1, "Hello");;
^^^^^^^
Error: This expression has type string but an expression was expected of type int

Notice that the error message for the tuple does not indicate which element is ill-typed, whereas the error message for the variant does.

Since I use lots of long tuples in my code, it would be very useful if OCaml gave more specific error messages in case of ill-typed tuple expressions.

@vicuna
Copy link
Author

vicuna commented Sep 6, 2011

Comment author: @xavierleroy

Thanks for the suggestion. I guess we could have a special "propagate expected type" mode for tuple expressions, just like we have one for constructors, functions, etc. But I'll let our typechecker experts decide.

@vicuna
Copy link
Author

vicuna commented Jun 1, 2012

Comment author: @garrigue

The use of type_expect has been generalized for type inference, and as a result one now gets the behavior you expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants