Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006173OCamlOCaml generalpublic2013-09-12 17:512015-11-23 22:49
Assigned Togarrigue 
PlatformOSOS Version
Product Version4.01.0 
Target Version4.02.0+devFixed in Version4.02.0+dev 
Summary0006173: Typing error message is worse that before
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
TagsNo tags attached.
Attached Files

- Relationships
has duplicate 0006295closed Unclear error message in 4.01.0 

-  Notes
furuse (reporter)
2013-09-19 05:00

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?
garrigue (manager)
2013-09-19 05:17

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?
furuse (reporter)
2013-09-19 05:19

I prefer the message you proposed.
johnwhitington (reporter)
2013-09-19 15:12
edited on: 2013-09-19 15:17

It is suggested by doligez in bug 0005936 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.

garrigue (manager)
2014-04-04 04:52

As explained in PR#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.
johnwhitington (reporter)
2015-01-04 12:12

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'.
xleroy (administrator)
2015-11-23 15:49

Any hope of addressing johnwhitington's latest example? I'm afraid not given the new type inference strategy introduced to handle constructor disambiguation.
octachron (reporter)
2015-11-23 22:42

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 ; .. ].
johnwhitington (reporter)
2015-11-23 22:49

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.

- Issue History
Date Modified Username Field Change
2013-09-12 17:51 johnwhitington New Issue
2013-09-19 05:00 furuse Note Added: 0010376
2013-09-19 05:17 garrigue Note Added: 0010377
2013-09-19 05:19 furuse Note Added: 0010378
2013-09-19 15:12 johnwhitington Note Added: 0010379
2013-09-19 15:17 johnwhitington Note Edited: 0010379 View Revisions
2014-01-16 22:26 yallop Relationship added has duplicate 0006295
2014-04-02 17:18 doligez Status new => acknowledged
2014-04-02 17:18 doligez Target Version => 4.02.0+dev
2014-04-04 04:52 garrigue Note Added: 0011217
2014-04-04 04:52 garrigue Status acknowledged => closed
2014-04-04 04:52 garrigue Assigned To => garrigue
2014-04-04 04:52 garrigue Resolution open => fixed
2014-04-04 04:52 garrigue Fixed in Version => 4.02.0+dev
2015-01-04 12:12 johnwhitington Note Added: 0013006
2015-01-04 12:12 johnwhitington Status closed => feedback
2015-01-04 12:12 johnwhitington Resolution fixed => reopened
2015-11-23 15:49 xleroy Note Added: 0014804
2015-11-23 22:42 octachron Note Added: 0014812
2015-11-23 22:49 johnwhitington Note Added: 0014813
2015-11-23 22:49 johnwhitington Status feedback => assigned

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker