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

Typing error message is worse that before #6173

Closed
vicuna opened this issue Sep 12, 2013 · 10 comments
Closed

Typing error message is worse that before #6173

vicuna opened this issue Sep 12, 2013 · 10 comments

Comments

@vicuna
Copy link

vicuna commented Sep 12, 2013

Original bug ID: 6173
Reporter: @johnwhitington
Assigned to: @garrigue
Status: assigned (set by @johnwhitington on 2015-11-23T21:49:16Z)
Resolution: reopened
Priority: normal
Severity: feature
Version: 4.01.0
Target version: later
Fixed in version: 4.02.0+dev
Category: typing
Has duplicate: #6295
Related to: #5936
Child of: #7338
Monitored by: @gasche @hcarty @dbuenzli

Bug description

OCaml version 4.01.0+rc1
# let f x = x @ [];;
val f : 'a list -> 'a list = <fun>
# f ();;
Error: The variant type list has no constructor ()

Is this related to the new variants work? Is it related to the fact that () is, unusually, a valid constructor (this has been debated before, I know)?

The previous behaviour is much less confusing.

 OCaml version 4.00.1

# let f x = x @ [];;
val f : 'a list -> 'a list = <fun>
# f ();;
Error: This expression has type unit but an expression was expected of type
         'a list
@vicuna
Copy link
Author

vicuna commented Sep 19, 2013

Comment author: furuse

I am also confused by this error message.

Is it possible to print which type the constructor (here ()) belongs to? Does the new variant name disambiguation thing prevent it?

@vicuna
Copy link
Author

vicuna commented Sep 19, 2013

Comment author: @garrigue

Indeed, the new variant name disambiguation allows using a constructor based on the type, even if this constructor is not the latest one defined, or not even in scope.

We could easily list up the types in scope which contain the said constructor.
But would this really help ?
Knowing that () is of type unit doesn't seem really relevant here.
Maybe it is just that the wording is not so good.
Something like:

Error: An expression of type 'a list was expected.
The constructor () does not belong to the variant type list.

might be clearer.

Note also that if it was just a typo, the error message is often better than before:

(Same 3 : int option);;

Error: The variant type option has no constructor Same
Did you mean Some?

@vicuna
Copy link
Author

vicuna commented Sep 19, 2013

Comment author: furuse

I prefer the message you proposed.

@vicuna
Copy link
Author

vicuna commented Sep 19, 2013

Comment author: @johnwhitington

It is suggested by doligez in bug #5936 that () as a constructor may be removed soon. This would fix this particular problem.

I didn't mean to suggest that the new message is in general a problem, I just think it's awfully confusing to the user when something as fundamental as unit is involved.

@vicuna
Copy link
Author

vicuna commented Apr 4, 2014

Comment author: @garrigue

As explained in #6173, the error message in trunk is now:

Error: This variant expression is expected to have type 'a list
The constructor () does not belong to type list

This seams clear enough.

@vicuna
Copy link
Author

vicuna commented Jan 4, 2015

Comment author: @johnwhitington

Even more confusing example, where the list constructor :: doesn't even appear explicitly in the source:

        OCaml version 4.03.0+dev5-2014-10-15

# let f () = ();;
val f : unit -> unit = <fun>
# f [1; 2; 3];;
Error: This variant expression is expected to have type unit
       The constructor :: does not belong to type unit

This used to be:

# let f () = ();;
val f : unit -> unit = <fun>
# f [1; 2; 3];;
Error: This expression has type 'a list
       but an expression was expected of type unit

which was better, because it mentioned the type 'list'.

@vicuna
Copy link
Author

vicuna commented Nov 23, 2015

Comment author: @xavierleroy

Any hope of addressing johnwhitington's latest example? I'm afraid not given the new type inference strategy introduced to handle constructor disambiguation.

@vicuna
Copy link
Author

vicuna commented Nov 23, 2015

Comment author: @Octachron

I have a naive question. Since the confusing apparition of (::) in the error message stems from special casing [ a ; ..] in the syntax, would it not make sense to also special case (::) in the error message? For instance, by adding a short note:

The constructor :: does not belong to type unit. Note: this constructor is used implicitely by the list syntax [ a ; .. ].

@vicuna
Copy link
Author

vicuna commented Nov 23, 2015

Comment author: @johnwhitington

A long-term solution to these problems might be to decorate the parse tree to indicate where syntactic sugar has been expanded during parsing.

If those decorations find their way unharmed through to the typed tree, the we could know the difference between a programmer writing "1::2::3::[]" and "[1; 2; 3]" in the source. Ditto for "fun x y -> x + y" vs "fun x -> fun y -> x + y". This difference would only be relevant when reporting an error, of course, not during typechecking itself.

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

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