caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* type unsoundness with constraints and polymorphic variants
@ 2008-02-11 20:03 Stephen Weeks
  2008-02-11 20:46 ` [Caml-list] " Markus Mottl
  2008-02-12  4:22 ` Jacques Garrigue
  0 siblings, 2 replies; 14+ messages in thread
From: Stephen Weeks @ 2008-02-11 20:03 UTC (permalink / raw)
  To: caml-list


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 ()


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

end of thread, other threads:[~2008-02-13 16:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-11 20:03 type unsoundness with constraints and polymorphic variants Stephen Weeks
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

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).