File: open_struct.ml

package info (click to toggle)
ocaml 5.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,372 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,396; asm: 5,462; makefile: 3,679; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (119 lines) | stat: -rw-r--r-- 2,070 bytes parent folder | download | duplicates (3)
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
(* TEST
 flags = "-dshape";
 expect;
*)

(* Everything that couldn't go anywhere else. *)

open struct
  module M = struct
    type t = A
  end
end
[%%expect{|
{}
module M : sig type t = A end
|}]

include M
[%%expect{|
{
 "t"[type] -> {<.0>
               "A"[constructor] -> {<.1>};
               };
 }
type t = M.t = A
|}]

module N = M
[%%expect{|
{
 "N"[module] ->
   Alias(<.3>
         {<.2>
          "t"[type] -> {<.0>
                        "A"[constructor] -> {<.1>};
                        };
          });
 }
module N = M
|}]

(* Not open structs, but the code handling the following is currently very
   similar to the one for open struct (i.e. calls [Env.enter_signature]), and
   so we are likely to encounter the same bugs, if any. *)

include struct
  module M' = struct
    type t = A
  end
end
[%%expect{|
{
 "M'"[module] -> {<.6>
                  "t"[type] -> {<.4>
                                "A"[constructor] -> {<.5>};
                                };
                  };
 }
module M' : sig type t = A end
|}]

module N' = M'
[%%expect{|
{
 "N'"[module] ->
   Alias(<.7>
         {<.6>
          "t"[type] -> {<.4>
                        "A"[constructor] -> {<.5>};
                        };
          });
 }
module N' = M'
|}]

module Test = struct
  module M = struct
    type t = A
  end
end
[%%expect{|
{
 "Test"[module] ->
   {<.11>
    "M"[module] -> {<.10>
                    "t"[type] -> {<.8>
                                  "A"[constructor] -> {<.9>};
                                  };
                    };
    };
 }
module Test : sig module M : sig type t = A end end
|}]

include Test
[%%expect{|
{
 "M"[module] -> {<.10>
                 "t"[type] -> {<.8>
                               "A"[constructor] -> {<.9>};
                               };
                 };
 }
module M = Test.M
|}]

module N = M
[%%expect{|
{
 "N"[module] ->
   Alias(<.12>
         {<.10>
          "t"[type] -> {<.8>
                        "A"[constructor] -> {<.9>};
                        };
          });
 }
module N = M
|}]