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

Soundness bug involving unpacking, functors and abstract module types #6427

Closed
vicuna opened this issue May 16, 2014 · 2 comments
Closed

Soundness bug involving unpacking, functors and abstract module types #6427

vicuna opened this issue May 16, 2014 · 2 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented May 16, 2014

Original bug ID: 6427
Reporter: @yallop
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:27:05Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.0+dev
Fixed in version: 4.02.0+dev
Category: typing

Bug description

Leo and I encountered the following problem in the 4.02.0 branch today:

$ cat bug.ml
let flag = ref false
module F(S : sig module type T end) (A : S.T) (B : S.T) =
struct
module X = (val if !flag then (module A) else (module B) : S.T)
end

module type S = sig type t val x : t end
module Float = struct type t = float let x = 0.0 end
module Int = struct type t = int let x = 0 end

module M = F(struct module type T = S end)

let () = flag := false
module M1 = M(Float)(Int)

let () = flag := true
module M2 = M(Float)(Int)

let _ = [| M2.X.x; M1.X.x |]
$ ocaml bug.ml
Segmentation fault (core dumped)

@vicuna
Copy link
Author

vicuna commented May 17, 2014

Comment author: @garrigue

Fixed in 4.02, at revision 14889.

This is a clever way to insert an abstract type in a signature...
How did you find it?
Mtype.contains_type was already checking for abstract module
type definitions, and for unresolved module types, but strangely
ignored this case (probably assumed a bad analogy with type
abbreviations).

@vicuna
Copy link
Author

vicuna commented May 19, 2014

Comment author: @yallop

Thanks for the quick fix! This one came up while investigating the boundaries of the module system rather than in a real program. Leo was teaching me how modules work, and I was trying to understand exactly what makes it impossible to write a module with the following type:

module False : functor (S : sig module type T end) -> S.T

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