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

module F(X : sig type t end) = struct
  let f (_ : X.t) = ()
end;;
[%%expect{|
module F : functor (X : sig type t end) -> sig val f : X.t -> unit end
|}]

module M = F(struct type t = T end);;
[%%expect{|
Line 1, characters 11-35:
1 | module M = F(struct type t = T end);;
               ^^^^^^^^^^^^^^^^^^^^^^^^
Error: This functor has type
       functor (X : sig type t end) -> sig val f : X.t -> unit end
       The parameter cannot be eliminated in the result type.
       Please bind the argument to a module identifier.
|}]

module M (X : sig type 'a t constraint 'a = float end) = struct
  module type S = sig
    type t = float
    val foo : t X.t
  end
end

module N = M (struct type 'a t = int constraint 'a = float end)

[%%expect{|
module M :
  functor (X : sig type 'a t constraint 'a = float end) ->
    sig module type S = sig type t = float val foo : t X.t end end
module N : sig module type S = sig type t = float val foo : int end end
|}]

type 'a always_int = int
module F (X : sig type t end) = struct type s = X.t always_int end
module M = F (struct type t = T end)
[%%expect{|
type 'a always_int = int
module F : functor (X : sig type t end) -> sig type s = X.t always_int end
module M : sig type s = int end
|}]

module M = struct
  module F (X : sig type t end) = X
  module Not_ok = F (struct type t = private [< `A] end)
end
[%%expect{|
module M :
  sig
    module F : functor (X : sig type t end) -> sig type t = X.t end
    module Not_ok : sig type t end
  end
|}]