caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Odd type error reporting
Date: Wed, 15 Jun 2016 09:37:22 +0200	[thread overview]
Message-ID: <f43edd10-1400-f846-35d4-ab2c09f029d8@tu-berlin.de> (raw)

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

             reply	other threads:[~2016-06-15  7:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15  7:37 Christoph Höger [this message]
2016-06-15  8:52 ` Leo White
2016-06-15  9:20   ` octachron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f43edd10-1400-f846-35d4-ab2c09f029d8@tu-berlin.de \
    --to=christoph.hoeger@tu-berlin.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).