summaryrefslogtreecommitdiff
path: root/testsuite/tests/match-exception-warnings/exhaustiveness_warnings.ml
blob: d6bcd397cacd85d1d1ed51489f4819bbea2bed8a (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
81
82
83
84
85
86
87
88
89
90
91
92
93
(* TEST
   * expect
*)

(** Test exhaustiveness.

    match clauses should continue to give warnings about inexhaustive
    value-matching clauses when there is an exception-matching clause
 *)

let test_match_exhaustiveness () =
    match None with
    | exception e -> ()
    | Some false -> ()
    | None -> ()
;;

[%%expect{|
Lines 8-11, characters 4-16:
 8 | ....match None with
 9 |     | exception e -> ()
10 |     | Some false -> ()
11 |     | None -> ()
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
Some true
val test_match_exhaustiveness : unit -> unit = <fun>
|}]
;;

let test_match_exhaustiveness_nest1 () =
    match None with
    | Some false -> ()
    | None | exception _ -> ()
;;

[%%expect{|
Lines 2-4, characters 4-30:
2 | ....match None with
3 |     | Some false -> ()
4 |     | None | exception _ -> ()
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
Some true
val test_match_exhaustiveness_nest1 : unit -> unit = <fun>
|}]
;;

let test_match_exhaustiveness_nest2 () =
    match None with
    | Some false | exception _ -> ()
    | None -> ()
;;

[%%expect{|
Lines 2-4, characters 4-16:
2 | ....match None with
3 |     | Some false | exception _ -> ()
4 |     | None -> ()
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
Some true
val test_match_exhaustiveness_nest2 : unit -> unit = <fun>
|}]
;;

let test_match_exhaustiveness_full () =
    match None with
    | exception e -> ()
    | Some false | exception _ -> ()
    | None | exception _ -> ()
;;

[%%expect{|
Lines 2-5, characters 4-30:
2 | ....match None with
3 |     | exception e -> ()
4 |     | Some false | exception _ -> ()
5 |     | None | exception _ -> ()
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
Some true
Line 4, characters 29-30:
4 |     | Some false | exception _ -> ()
                                 ^
Warning 11 [redundant-case]: this match case is unused.
Line 5, characters 23-24:
5 |     | None | exception _ -> ()
                           ^
Warning 11 [redundant-case]: this match case is unused.
val test_match_exhaustiveness_full : unit -> unit = <fun>
|}]
;;