summaryrefslogtreecommitdiffstats
path: root/testsuite/tests/typing-extensions/extensions.ml.reference
blob: 25af292de1874e61583ca6a9433e3d5e771fe554 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

#     type foo = ..
#         type foo += A | B of int
#           val is_a : foo -> bool = <fun>
#         type foo
#     Characters 13-21:
  type foo += A of int (* Error type is not open *)
              ^^^^^^^^
Error: Cannot extend type definition foo
#         type 'a foo = ..
#     Characters 1-30:
  type ('a, 'b) foo += A of int (* Error: type parameter mismatch *)
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This extension does not match the definition of type foo
       They have different arities.
#                 module type S = sig type foo type foo += A of float end
#                 Characters 84-106:
    type foo += B of float (* Error foo does not have an extensible type *)
    ^^^^^^^^^^^^^^^^^^^^^^
Error: Type foo is not extensible
#         type foo = ..
#                     module M :
  sig
    type foo += A of int | B of string
    type foo += C of int | D of float
    
  end
#                     module type S =
  sig
    type foo += B of string | C of int
    type foo += D of float
    type foo += A of int
  end
#     module M_S : S
#         type 'a foo = ..
#         type _ foo += A : int -> int foo | B : int foo
#           val get_num : 'a foo -> 'a -> 'a option = <fun>
#         type 'a foo = .. constraint 'a = [> `Var ]
#     type 'a foo += A of 'a
#     Characters 11-12:
  let a = A 9 (* ERROR: Constraints not met *)
            ^
Error: This expression has type int but an expression was expected of type
         [> `Var ]
#     Characters 20-23:
  type 'a foo += B : int foo (* ERROR: Constraints not met *)
                     ^^^
Error: This type int should be an instance of type [> `Var ]
#         type foo = ..
#     module M : sig type foo += A of int end
#     val a1 : foo = M.A 10
#     module type S = sig type foo += private A of int end
#     module M_S : S
#           val is_s : foo -> bool = <fun>
#     Characters 10-18:
  let a2 = M_S.A 20 (* ERROR: Cannot create a value using a private constructor *)
           ^^^^^^^^
Error: Cannot create values of the private type foo
#         type foo = ..
#     module M : sig type foo += A1 of int end
#     type foo += A2 of int
#     type bar = ..
#     Characters 18-22:
  type bar += A3 = M.A1    (* Error: rebind wrong type *)
                   ^^^^
Error: The constructor M.A1 has type foo but was expected to be of type bar
#     module M : sig type foo += private B1 of int end
#     type foo += private B2 of int
#     Characters 18-22:
  type foo += B3 = M.B1  (* Error: rebind private extension *)
                   ^^^^
Error: The constructor M.B1 is private
#     Characters 13-24:
  type foo += C = Unknown  (* Error: unbound extension *)
              ^^^^^^^^^^^
Error: Unbound constructor Unknown
#                       module M : sig type foo type foo += A1 of int end
type M.foo += A2 of int
type 'a foo = ..
#     type 'a foo1 = 'a foo = ..
#     type 'a foo2 = 'a foo = ..
#           type 'a foo1 += A of int | B of 'a | C : int foo1
#           type 'a foo2 += D of int | E of 'a | F : int foo2
#         type +'a foo = ..
#     type 'a foo += A of (int -> 'a)
#     Characters 1-32:
  type 'a foo += B of ('a -> int) (* ERROR: Parameter variances are not satisfied *)
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: In this definition, expected parameter variances are not satisfied.
       The 1st type parameter was expected to be covariant,
       but it is injective contravariant.
#     Characters 1-40:
  type _ foo += C : ('a -> int) -> 'a foo (* ERROR: Parameter variances are not satisfied *)
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: In this definition, expected parameter variances are not satisfied.
       The 1st type parameter was expected to be covariant,
       but it is injective contravariant.
#     type 'a bar = ..
#     Characters 1-33:
  type +'a bar += D of (int -> 'a) (* ERROR: type variances do not match *)
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This extension does not match the definition of type bar
       Their variances do not agree.
#                       module M : sig type exn += Foo of int * float | Bar : 'a list -> exn  end
#                   module M :
  sig exception Bar : 'a list -> exn exception Foo of int * float end
#     exception Foo of int * float
#     exception Bar : 'a list -> exn
#                   module M : sig type exn += Foo of int * float | Bar : 'a list -> exn  end
#         type foo = ..
#         type foo += Foo of int * int option | Bar of int option
#     val x : foo * foo = (Foo (3, Some 4), Bar (Some 5))
#     type foo += Foo of string
#     val y : foo * foo = (<extension>, Bar (Some 5))
#     exception Foo of int * int option
#     exception Bar of int option
#     val x : exn * exn = (Foo (3, Some 4), Bar (Some 5))
#     type foo += Foo of string
#     val y : exn * exn = (Foo (3, _), Bar (Some 5))
#         type foo = ..
#         type foo += Foo | Bar of int
#     val n1 : string = "Foo"
#     val n2 : string = "Bar"
#     val t : bool = true
#     val f : bool = false
#         val is_foo : 'a -> bool = <fun>
type foo += Foo
#     val f : bool = false
#     Exception: Invalid_argument "Obj.extension_name".
#     Exception: Invalid_argument "Obj.extension_id".
#