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

type ('a, 'b) segment =
  | SegNil : ('a, 'a) segment
  | SegCons : ('a * 'a, 'b) segment -> ('a, 'b) segment

let color : type a b . (a, b) segment -> int = function
  | SegNil -> 0
  | SegCons SegNil -> 0
  | SegCons _ -> 0
[%%expect{|
type ('a, 'b) segment =
    SegNil : ('a, 'a) segment
  | SegCons : ('a * 'a, 'b) segment -> ('a, 'b) segment
val color : ('a, 'b) segment -> int = <fun>
|}]

(* Fail *)
let color (* : type a b . (a, b) segment -> int *) = function
  | SegNil -> 0
  | SegCons SegNil -> 0
  | SegCons _ -> 0
[%%expect{|
Line 3, characters 12-18:
3 |   | SegCons SegNil -> 0
                ^^^^^^
Error: This pattern matches values of type ('a * 'a, 'a * 'a) segment
       but a pattern was expected which matches values of type
         ('a * 'a, 'a) segment
       The type variable 'a occurs inside 'a * 'a
|}]