summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-modules/unroll_private_abbrev.ml
blob: cb9bf74d5dd3aec20a3ce87485e83b09a3423b3e (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(* TEST
 expect;
*)

module M : sig
  type t = private [ `Bar of 'a | `Foo ] as 'a
  val bar : t
end = struct
  type t = [ `Bar of 'a | `Foo ] as 'a
  let bar = `Bar `Foo
end;;
[%%expect{|
module M : sig type t = private [ `Bar of 'a | `Foo ] as 'a val bar : t end
|}]

let y =
  match (M.bar :> [ `Bar of 'a | `Foo ] as 'a) with
  | `Bar x -> x
  | `Foo -> assert false
;;
[%%expect{|
val y : [ `Bar of 'a | `Foo ] as 'a = `Foo
|}]

let y =
  match (M.bar :> [ `Bar of M.t | `Foo ]) with
  | `Bar x -> x
  | `Foo -> assert false
;;
[%%expect{|
Line 2, characters 8-41:
2 |   match (M.bar :> [ `Bar of M.t | `Foo ]) with
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Type M.t is not a subtype of [ `Bar of M.t | `Foo ]
       Type M.t = [ `Bar of M.t | `Foo ] is not a subtype of M.t
|}]

module F(X : sig end) : sig
  type s = private [ `Bar of 'a | `Foo ] as 'a

  val from : M.t -> s
  val to_  : s -> M.t
end = struct
  type s = M.t

  let from x = x
  let to_ x = x
end;;
[%%expect{|
module F :
  functor (X : sig end) ->
    sig
      type s = private [ `Bar of 'a | `Foo ] as 'a
      val from : M.t -> s
      val to_ : s -> M.t
    end
|}]

module N = F(struct end);;
[%%expect{|
module N :
  sig
    type s = private [ `Bar of 'a | `Foo ] as 'a
    val from : M.t -> s
    val to_ : s -> M.t
  end
|}]

let y =
  match (N.from M.bar :> [ `Bar of N.s | `Foo ]) with
  | `Bar x -> N.to_ x
  | `Foo -> assert false
;;
[%%expect{|
Line 2, characters 8-48:
2 |   match (N.from M.bar :> [ `Bar of N.s | `Foo ]) with
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Type N.s is not a subtype of [ `Bar of N.s | `Foo ]
       Type N.s = [ `Bar of N.s | `Foo ] is not a subtype of N.s
|}]