MantisBT - OCaml
View Issue Details
0007414OCamltypingpublic2016-11-16 12:002016-12-10 02:55
lpw25 
garrigue 
normalminoralways
resolvedfixed 
4.04.0 
4.05.0 +dev/beta1/beta2/beta3/rc1 
0007414: Soundness bug with non-generalized type variable and functors
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
  end

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

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

  let switch = ref true

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

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

  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'.Choice.show x)) !(!N'.r)
No tags attached.
related to 0006752resolved garrigue Extensible variant types and scope escaping 
Issue History
2016-11-16 12:00lpw25New Issue
2016-11-16 13:30shinwellAssigned To => garrigue
2016-11-16 13:30shinwellStatusnew => assigned
2016-11-19 01:31garrigueNote Added: 0016594
2016-11-19 01:31garrigueStatusassigned => confirmed
2016-11-21 14:22garrigueNote Added: 0016598
2016-11-21 14:22garrigueStatusconfirmed => resolved
2016-11-21 14:22garrigueFixed in Version => 4.05.0 +dev/beta1/beta2/beta3/rc1
2016-11-21 14:22garrigueResolutionopen => fixed
2016-12-10 02:55garrigueRelationship addedrelated to 0006752
2017-02-23 16:45doligezCategoryOCaml typing => typing

Notes
(0016594)
garrigue   
2016-11-19 01:31   
I've created a pull-request https://github.com/ocaml/ocaml/pull/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.
(0016598)
garrigue   
2016-11-21 14:22   
Merged the pull request in commit 2bd22967.
Now handled by a visit of the signature rather than by Subst.