caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Odd type error reporting
@ 2016-06-15  7:37 Christoph Höger
  2016-06-15  8:52 ` Leo White
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Höger @ 2016-06-15  7:37 UTC (permalink / raw)
  To: caml users

Dear all,

It just took me 30min to figure out a rather simple type-error in my
code. It was complicated by ocamlc's strange error reporting. Consider
this example:

% cat error.ml
type foo = { foo : int }
type bar = { bar : int }
type baz = { f : int -> foo }

let () = { f = fun bar -> { bar } }
% ocamlc error.ml
File "error.ml", line 5, characters 28-31:
Error: This record expression is expected to have type baz
       The field bar does not belong to type foo



ocamlc correctly spots the "bar" in the last line as the source of the
error. However, it says, it is expected to have type "baz", but that is
the surrounding constructor.

In fact, the "correct" error is:

File "error.ml", line 5, characters 26-33:
Error: This record expression is expected to have type foo
       The field bar does not belong to type foo



Obviously, in a perfect world, the wrongly labeled field should be
pointed out as well (kind of a sub-error). However, it seems problematic
that the outermost record-mismatch is reported.

Is this a known bug/feature? Does it change in later versions (I am on
4.02.3 now)?

thanks,

Christoph
-- 
Christoph Höger

Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen

Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin

Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-15  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-15  7:37 [Caml-list] Odd type error reporting Christoph Höger
2016-06-15  8:52 ` Leo White
2016-06-15  9:20   ` octachron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).