Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006171OCamltypingpublic2013-09-11 18:062016-12-07 11:47
Assigned Togarrigue 
PlatformOSOS Version
Product Version4.01.0+beta/+rc 
Target Version4.02.2+dev / +rc1Fixed in Version4.03.0+dev / +beta1 
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
File "", 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
has duplicate 0006734closedwhitequark Extremely cryptic error on type escaping before its definition 

-  Notes
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.
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
           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.

garrigue (manager)
2015-01-17 04:27

Fixed as suggest by Leo in trunk at revision 15782.

- 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 / +rc1
2015-01-02 11:57 whitequark Relationship added has duplicate 0006734
2015-01-17 04:27 garrigue Note Added: 0013129
2015-01-17 04:27 garrigue Status confirmed => resolved
2015-01-17 04:27 garrigue Resolution open => fixed
2015-01-17 04:28 garrigue Fixed in Version => 4.03.0+dev / +beta1
2016-12-07 11:47 xleroy Status resolved => closed
2017-02-23 16:45 doligez Category OCaml typing => typing

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker