summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-modules-bugs/pr7414_bad.ml
blob: 7bc294599d960619b02acf47c083666669aed443 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(* TEST
flags = " -w -a "
ocamlc_byte_exit_status = "2"
* setup-ocamlc.byte-build-env
** ocamlc.byte
*** check-ocamlc.byte-output
*)

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 = Int.to_string 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)
;; (* fail *)

(* would cause segfault
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)
*)