Skip to content

ocamlc -i can generate a wrong signature #6323

@vicuna

Description

@vicuna

Original bug ID: 6323
Reporter: pw374
Assigned to: @garrigue
Status: closed (set by @garrigue on 2017-03-14T03:20:35Z)
Resolution: duplicate
Priority: normal
Severity: minor
Version: 4.01.0
Target version: later
Category: typing
Duplicate of: #4791
Has duplicate: #7402
Related to: #6324
Monitored by: @hcarty

Bug description

Sometimes 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 reproduce

This 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 information

I 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".

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions