caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Stephen Weeks" <sweeks@janestcapital.com>
To: caml-list@inria.fr
Subject: type unsoundness with constraints and polymorphic variants
Date: Mon, 11 Feb 2008 15:03:57 -0500	[thread overview]
Message-ID: <18352.43565.401296.820373@nyc-qws-r03.delacy.com> (raw)


We've hit a type unsoundness in OCaml that can easily cause a segfault
at runtime.  It came up in some code that uses phantom types to
express whether or not a structure can be mutated and the identity
functions to convert from a read-write object to a read-only view.

Here is a distillation of the bug.  If you compile this, you get a
warning about line 11 being an unused case.  If you then run the
resulting executable, you get a segfault.

--------------------------------------------------------------------------------
type 'a t = 'a constraint 'a = [< `X | `Y of unit -> unit ]

module M : sig
  val f : 'a t -> [ `Y of unit -> unit ] t
end = struct
  let f x = x
end

let () =
  match M.f `X with
  | `X -> ()  (* line 11 *)
  | `Y f -> f ()


             reply	other threads:[~2008-02-11 20:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-11 20:03 Stephen Weeks [this message]
2008-02-11 20:46 ` [Caml-list] " Markus Mottl
2008-02-12  4:22 ` Jacques Garrigue
2008-02-12 10:35   ` Andrej Bauer
2008-02-12 14:43     ` Luc Maranget
2008-02-13  8:00     ` Jacques Garrigue
2008-02-13 14:15       ` Christopher L Conway
2008-02-13 14:18         ` Michael Hicks
2008-02-13 14:22           ` David Teller
2008-02-13 14:35           ` Till Varoquaux
2008-02-13 14:52             ` Michael Hicks
2008-02-13 14:53             ` Mattias Engdegård
2008-02-13 15:55               ` Christopher L Conway
2008-02-13 16:53             ` Stefano Zacchiroli

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=18352.43565.401296.820373@nyc-qws-r03.delacy.com \
    --to=sweeks@janestcapital.com \
    --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).