Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006323OCamlOCaml typingpublic2014-02-06 18:592014-07-16 17:55
Reporterpw374 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version4.01.0 
Target Versionafter-4.02.0Fixed in Version 
Summary0006323: ocamlc -i can generate a wrong signature
DescriptionSometimes ocamlc -i generates a wrong signature, and then, either the compiler will give a "helpful" error message by saying something like ... X.t ... is not the same as ... t ..., or it says something like "val x : t is not included in va x : t", which is not helpful at all.
Steps To ReproduceThis generates a rather understandable error:
cat > a.ml <<EOF
type t = A

module X =
struct
  type t = B
  let x = A
end
EOF
ocamlc -i a.ml > a.mli
ocamlc -c a.mli
ocamlc -c a.ml # this one fails but I'm nearly okay with it because it's possible to guess what's wrong from the error message and fix it.


But this gives an error that's very hard to understand, especially when the program is not that small:

cat > b.ml <<EOF
type 'a t = B of 'a t list

let rec foo f = function
  | B(v)::tl -> B(foo f v)::foo f tl
  | [] -> []

module DT = struct
  type 'a t = {bar : 'a}
  let p t = foo (fun x -> x) t
end
EOF
ocamlc -i b.ml > b.mli
ocamlc -c b.mli
ocamlc -c b.ml # this one fails and the error message bothers me a lot because the error message is virtually impossible to understand when the program is fairly larger than this toy example.
Additional InformationI guess that either ocamlc -i should never generate an interface that won't compile, or the error message for the second example (i.e., b.ml) should be improved.

In the case where it's chosen that it's acceptable for ocamlc -i to generate interfaces that won't compile, I believe it should at least give warnings or provide ways to track down the "generated errors".
TagsNo tags attached.
Attached Files

- Relationships
related to 0006416acknowledged The same string can mean different types in the same error message 
related to 0006324acknowledged Module aliasing and ability to reference the current and parent modules 

-  Notes
(0010904)
kaustuv (reporter)
2014-02-06 19:15

I've run into this issue numerous times as well. I've stopped naming my types "t" as a result of this and a related issue [1].

I think the compiler should reject a module whose visible values have un-namable types. This augments the current heuristic that the same type name cannot be introduced in the same scope more than once.


[1] functors like Set.Make cannot be instantiated with a module with a carrier type of "t" if "t" is already visible. For some reason, type t = t is taken as a recursive type abbreviation, which breaks a common use case to support a baroque corner case (-rectypes)!
(0011861)
doligez (administrator)
2014-07-16 17:55

ocamlc -i originates as a kind of "verbose" option and was not implemented as a well-thought-out must-work-in-all-cases interface-generation tool.
We might want to turn it into one, but that will probably involve a large amount of work.

- Issue History
Date Modified Username Field Change
2014-02-06 18:59 pw374 New Issue
2014-02-06 19:15 kaustuv Note Added: 0010904
2014-02-19 20:25 doligez Relationship added related to 0006324
2014-05-30 14:14 shinwell Relationship added related to 0006416
2014-05-30 14:16 shinwell Status new => acknowledged
2014-07-16 17:55 doligez Note Added: 0011861
2014-07-16 17:55 doligez Target Version => after-4.02.0


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker