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 breakage with modules #6817

Closed
vicuna opened this issue Mar 23, 2015 · 4 comments
Closed

GADT exhaustiveness breakage with modules #6817

vicuna opened this issue Mar 23, 2015 · 4 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Mar 23, 2015

Original bug ID: 6817
Reporter: @chambart
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2016-12-07T10:47:26Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0+dev / +beta1
Fixed in version: 4.02.2+dev / +rc1
Category: typing
Monitored by: @diml @yallop

Bug description

This code is correctly checked for exhaustiveness if defined like this. But
if nil is declared in another module, it breaks

type nil

type _ s =
| Nil : nil s
| Cons : 't s -> ('h -> 't) s

type ('stack, 'typ) var =
| Head : (('typ -> ) s, 'typ) var
| Tail : ('tail s, 'typ) var -> ((
-> 'tail) s, 'typ) var

type _ lst =
| CNil : nil lst
| CCons : 'h * ('t lst) -> ('h -> 't) lst

let rec get_var : type stk ret. (stk s, ret) var -> stk lst -> ret = fun n s ->
match n, s with
| Head, CCons (h, ) -> h
| Tail n', CCons (
, t) -> get_var n' t

For instance if we replace type nil with

module A = struct
type nil
end
open A

Or even

module A = struct
type nil = Cstr
end
open A

Notice that type nil = unit works.

File attachments

@vicuna
Copy link
Author

vicuna commented Mar 23, 2015

Comment author: @lpw25

The first case is the correct behaviour, because an abstract type from another module could be equal to a function type. The second case could probably be improved, since a type with a Cstr constructor could not be equal to a function type.

@vicuna
Copy link
Author

vicuna commented Mar 24, 2015

Comment author: @lpw25

The attached patch fixes the second case. It seems sound to me, since a structural type cannot be equal to a datatype.

@vicuna
Copy link
Author

vicuna commented Mar 25, 2015

Comment author: @garrigue

Fixed as suggested in trunk and 4.02, at revisions 15959 and 15960.

@vicuna
Copy link
Author

vicuna commented Mar 26, 2015

Comment author: @chambart

Thanks you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants