summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-gadts/pr7269.ml
blob: da2456e4a6fd0dd7b0b586a1caa5c1a174ba9054 (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
(* TEST
   * expect
*)

type s = [`A | `B] and sub = [`B];;
type +'a t = T : [< `Conj of 'a & sub | `Other of string] -> 'a t;; (* ok *)

let f (T (`Other msg) : s t) = print_string msg;;
let _ = f (T (`Conj `B) :> s t);; (* warn *)
[%%expect{|
type s = [ `A | `B ]
and sub = [ `B ]
type +'a t = T : [< `Conj of 'a & sub | `Other of string ] -> 'a t
Line _, characters 6-47:
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
T (`Conj _)
val f : s t -> unit = <fun>
Exception: Match_failure ("", 4, 6).
|}];;

module M : sig
  type s
  type t = T : [< `Conj of int & s | `Other of string] -> t
  val x : t
end = struct
  type s = int
  type t = T : [< `Conj of int | `Other of string] -> t
  let x = T (`Conj 42)
end;;

let () = M.(match x with T (`Other msg) -> print_string msg);; (* warn *)
[%%expect{|
module M :
  sig
    type s
    type t = T : [< `Conj of int & s | `Other of string ] -> t
    val x : t
  end
Line _, characters 12-59:
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
T (`Conj _)
Exception: Match_failure ("", 11, 12).
|}];;


module M : sig
  type s
  type elim =
      { ex : 'a . ([<`Conj of int & s | `Other of string] as 'a) -> unit }
  val e : elim -> unit
end = struct
  type s = int
  type elim =
      { ex : 'a . (([<`Conj of int | `Other of string] as 'a) -> unit) }
  let e { ex } = ex (`Conj 42 : [`Conj of int])
end;;

let () = M.(e { ex = fun (`Other msg) -> print_string msg });; (* warn *)
[%%expect{|
module M :
  sig
    type s
    type elim = {
      ex : 'a. ([< `Conj of int & s | `Other of string ] as 'a) -> unit;
    }
    val e : elim -> unit
  end
Line _, characters 21-57:
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
`Conj _
Exception: Match_failure ("", 13, 21).
|}];;