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

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

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

This comment has been minimized.

Copy link
Collaborator Author

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

This comment has been minimized.

Copy link
Collaborator Author

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

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 25, 2015

Comment author: @garrigue

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

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 26, 2015

Comment author: @chambart

Thanks you !

@vicuna vicuna closed this Dec 7, 2016

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

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.