From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: sweeks@janestcapital.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] type unsoundness with constraints and polymorphic variants
Date: Tue, 12 Feb 2008 13:22:25 +0900 (JST) [thread overview]
Message-ID: <20080212.132225.27792058.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <18352.43565.401296.820373@nyc-qws-r03.delacy.com>
From: "Stephen Weeks" <sweeks@janestcapital.com>
> 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 ()
Thanks for the report. It's so clearly a bug that it's strange it was
not found earlier :-(
A shorter version (without constraints) is:
module M : sig val f : [< `A | `B] -> [`A] end = struct let f x = x end
This is now fixed in CVS, and should go in 3.10.2.
Cheers,
Jacques Garrigue
BTW, there is a bug tracking system...
next prev parent reply other threads:[~2008-02-12 4:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-11 20:03 Stephen Weeks
2008-02-11 20:46 ` [Caml-list] " Markus Mottl
2008-02-12 4:22 ` Jacques Garrigue [this message]
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=20080212.132225.27792058.garrigue@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=sweeks@janestcapital.com \
/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