Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006171OCamlOCaml typingpublic2013-09-11 18:062014-09-23 17:29
Reporterjohnwhitington 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusconfirmedResolutionopen 
PlatformOSOS Version
Product Version4.01.0+beta/+rc 
Target Version4.02.2+devFixed in Version 
Summary0006171: Error message confusing for the beginner when a type escapes its scope.
DescriptionI'd only had to deal with this error when using the module system until now -- I hadn't realised how easily it could be encountered with a single reference.

The first line of the message in particular is rather confusing:

let x = ref []

type t = A

let store () =
  x := A::!x

feast:~ john$ ocamlc mess.ml
File "mess.ml", line 6, characters 7-8:
Error: This expression has type t but an expression was expected of type t
       The type constructor t would escape its scope

Perhaps skip the first line of the error message since it's confusing and add a clarification -- something like "A type can only be used after it has been introduced."?

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0010342)
garrigue (manager)
2013-09-12 00:19

Reporting of unification errors is fundamentally broken: it is hard to see where the error comes from, and specific cases are poorly handled.
I hope to be able to fix it, but this would need some deep changes.
Quick fixes do not help much.
For instance here, if we remove the first line, we lose the type of the expression, which can be informative.
(0010358)
lpw25 (developer)
2013-09-16 16:04
edited on: 2013-09-16 16:37

It wouldn't help much in this case, but could the error at least mention the type that it tried to unify t with, rather than t itself.

So, for example:

    # let f b (x: 'x) =
        let module M = struct
          type t = A
        end in
          if b then x else M.A;;
            Characters 96-99:
            if b then x else M.A;;
                             ^^^
    Error: This expression has type M.t but an expression was expected of type
             'x
           The type constructor M.t would escape its scope

This information is often quite useful, and I don't think it would be hard to expose.


- Issue History
Date Modified Username Field Change
2013-09-11 18:06 johnwhitington New Issue
2013-09-12 00:19 garrigue Note Added: 0010342
2013-09-12 00:19 garrigue Assigned To => garrigue
2013-09-12 00:19 garrigue Status new => acknowledged
2013-09-16 16:04 lpw25 Note Added: 0010358
2013-09-16 16:33 lpw25 Note Edited: 0010358 View Revisions
2013-09-16 16:37 lpw25 Note Edited: 0010358 View Revisions
2014-07-16 18:35 doligez Target Version => 4.02.1+dev
2014-09-04 00:25 doligez Target Version 4.02.1+dev => undecided
2014-09-23 17:29 doligez Status acknowledged => confirmed
2014-09-23 17:29 doligez Target Version undecided => 4.02.2+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker