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

Closed
vicuna opened this issue Jan 16, 2013 · 1 comment
Closed

GADT exhaustiveness check is broken #5892

vicuna opened this issue Jan 16, 2013 · 1 comment
Assignees
Labels
bug typing typing-GADTS GADT typing and exhaustiveness bugs

Comments

@vicuna
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:

testList.ml:

module type Num = sig
type nil
type _ cons
end

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

end

module Bad = struct
type nil
type _ cons = nil
end

module Types = Make(Bad)

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

testList.mli:

module Types : sig

type _ cons

type nil

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

end

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

test.ml:

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 testList.ml
$ ocamlc -c test.ml
$ ./a.out
Segmentation fault

@vicuna
Copy link
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 predef.ml are incompatible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug typing typing-GADTS GADT typing and exhaustiveness bugs
Projects
None yet
Development

No branches or pull requests

3 participants