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

Escaped existential type #7222

Closed
vicuna opened this Issue Apr 11, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

vicuna commented Apr 11, 2016

Original bug ID: 7222
Reporter: @Octachron
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-09-24T15:32:19Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 4.02.3
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: typing
Monitored by: @gasche @hcarty

Bug description

The following code leads to a toplevel function with existential type within its type:
"
type +'a n = private int
type nil = private Nil_type
type (,) elt =
| Elt_fine: 'nat n -> ('l,'nat * 'l) elt
| Elt: 'nat n -> ('l,'nat -> 'l) elt
type _ t = Nil : nil t | Cons : ('x, 'fx) elt * 'x t -> 'fx t

let undetected: ('a -> 'b -> nil) t -> 'a n -> 'b n -> unit = fun sh i j ->
let Cons(Elt dim, _) = sh in ()
"
The type inferred for "undetected" is "('a -> $'b -> nil) t -> 'a n -> $'b n -> unit ".

As far as I understand, the existential type "$'b" should never appear in the type of a toplevel function and this is a typing error.

Moreover, slightly altering the code to

"
let detected: ('a * 'b * nil) t -> 'a n -> 'b n -> unit = fun sh i j ->
let Cons(Elt_fine dim, _) = sh in ()
"
triggers a compiler error about the existential type leaving its scope.
The same problem persists from version 4.02.3 to the beta2 version of 4.03.0.

As a supplementary information, calling the full version of this function accross module boundary triggered an internal assertion failure at (File "typing/typecore.ml", line 1903, characters 65-71) within the 4.02.3 compiler.
Unfortunately, I could not try the original code with the 4.03 beta compilers.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Apr 12, 2016

Comment author: @Octachron

Correction, the second example also exhibits leaked existential type once its type is corrected to
"
let (also_not_)detected: ('a * ('b * nil)) t -> 'a n -> 'b n -> unit
= fun sh i j -> let Cons(Elt_fine dim, _) = sh in ()
(val detected: ('a * ($'b * nil)) t -> 'a n -> $'b n -> unit)
"

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Apr 15, 2016

Comment author: @garrigue

Fixed in 4.03 and trunk by commits f61df10 and 390d0fa.

Error messages could be improved...

@vicuna vicuna closed this Sep 24, 2017

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added this to the 4.03.0 milestone 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.