Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GADT exhaustiveness check is broken #5892

vicuna opened this Issue Jan 16, 2013 · 1 comment


None yet
2 participants
Copy link

vicuna commented Jan 16, 2013

Original bug ID: 5892
Reporter: @lpw25
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:18:42Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.00.1
Fixed in version: 4.00.2+dev
Category: typing
Related to: #5853
Child of: #5998
Monitored by: @gasche @diml

Bug description

I haven't explored the issue fully, but there is something wrong with the GADT exhaustivness check. The problem is probably in Ctype.mcomp.

The following files will give a segmentation fault when run:

module type Num = sig
type nil
type _ cons

module Make (N: Num) = struct
type nil = N.nil
type 'a cons = 'a N.cons

type ('a,'b) t =
| Cons : 'a * ('a, 'b) t -> ('a, 'b N.cons) t
| Nil : ('a, N.nil) t


module Bad = struct
type nil
type _ cons = nil

module Types = Make(Bad)

let bad: (int, Types.nil Types.cons) Types.t = Types.Nil


module Types : sig

type _ cons

type nil

type ('a,_) t =
| Cons : 'a * ('a, 'b) t -> ('a, 'b cons) t
| Nil : ('a, nil) t


val bad: (int, Types.nil Types.cons) Types.t

let hd: type a b . (a, b TestList.Types.cons) TestList.Types.t -> a =
fun (TestList.Types.Cons(x,_)) -> x

let _ = hd TestList.bad

Steps to reproduce

$ ocamlc -c testList.mli
$ ocamlc -c
$ ocamlc -c
$ ./a.out
Segmentation fault


This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jan 16, 2013

Comment author: @garrigue

Fixed in 4.00 and trunk, revisions 13250 and 13252.

Ctype.in_pervasives was broken: looking for a path TestList.nil in the empty environment also looks it up inside testList.cmi...
Now we also require that the path has no prefix (subsumed by Ctype.in_current_module).
As a result, Pervasives.in_channel and Pervasives.out_channel are no longer recognized as incompatible types (only those in are incompatible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.