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 with non-generalized type variable and functors #7414

vicuna opened this issue Nov 16, 2016 · 2 comments


None yet
2 participants
Copy link

commented Nov 16, 2016

Original bug ID: 7414
Reporter: @lpw25
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2016-11-21T13:22:14Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.04.0
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: typing
Related to: #6752
Monitored by: @gasche @yallop

Bug description

The interplay between non-generalized type variables and functors seems ill defined and unsound. Using first-class modules we can get a segfault:

module type T = sig
type t
val x : t
val show : t -> string

module Int = struct
type t = int
let x = 0
let show x = string_of_int x

module String = struct
type t = string
let x = "Hello"
let show x = x

let switch = ref true

module Choose () = struct
module Choice =
(val if !switch then (module Int : T)
else (module String : T))
let r = ref (ref [])

module type S = sig
module Choice : T
val r : Choice.t list ref ref

module Force (X : functor () -> S) = struct end

module M = Choose ()

let () = switch := false

module N = Choose ()

let () = N.r := !M.r

module Ignore = Force(Choose)

module M' = (M : S)

let () = (!M'.r) := [M'.Choice.x]

module N' = (N : S)

let () = List.iter (fun x -> print_string (N' x)) !(!N'.r)


This comment has been minimized.

Copy link

commented Nov 19, 2016

Comment author: @garrigue

I've created a pull-request #929 with a fix.
Note that the current fix is not very efficient, so I will revise it before merging,
to use an iterator rather than Subst.modtype.


This comment has been minimized.

Copy link

commented Nov 21, 2016

Comment author: @garrigue

Merged the pull request in commit 2bd2296.
Now handled by a visit of the signature rather than by Subst.

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.