Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_virtual_type_variance.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import kernel
16
17 class G
18 type E: nullable Object
19 var e: nullable E = null
20 end
21
22 class GA
23 super G
24 redef type E: A
25 end
26 class GB
27 super GA
28 redef type E: B
29 end
30 class GC
31 super GA
32 redef type E: C
33 end
34
35 class GGA
36 super G
37 redef type E: GA
38 end
39 class GGB
40 super GGA
41 redef type E: GB
42 end
43
44 class A
45 fun foo do 1.output
46 end
47 class B
48 super A
49 redef fun foo do 2.output
50 fun bar do 20.output
51 end
52 class C
53 super A
54 redef fun foo do 3.output
55 fun function_never_called do 300.output
56 end
57
58 var b: B = new B
59 var gb: GB = new GB
60 var gbe: nullable B
61
62 gb.e = b
63 gbe = gb.e
64 gbe.foo
65 gbe.bar
66
67 var a: A = b
68
69 #alt1#gb.e = a.as(B)
70 #alt1#gbe = gb.e
71 #alt1#gbe.foo
72 #alt1#gbe.bar
73
74 var ga: GA = gb
75
76 ga.e = a
77 gbe = gb.e
78 gbe.foo
79 gbe.bar
80
81 var c: A = new C
82
83 #alt2#gb.e = c.as(B)
84 #alt2#gbe = gb.e
85 #alt2#gbe.foo
86 #alt3#gbe.bar
87
88 #alt3#ga.e = c
89 #alt3#gbe = gb.e
90 #alt3#gbe.foo
91 #alt3#gbe.bar
92
93 var ggb: GGB = new GGB
94 var ggbe: nullable GB
95 var ggbee: nullable B
96
97 ggb.e = gb
98 ggbe = ggb.e
99 ggbee = ggbe.e
100 ggbee.foo
101 ggbee.bar
102
103 #alt4#ggb.e = ga.as(GB)
104 #alt4#ggbe = ggb.e
105 #alt4#ggbee = ggbe.e
106 #alt4#ggbee.foo
107 #alt4#ggbee.bar
108
109 var gga: GGA = ggb
110
111 gga.e = ga
112 ggbe = ggb.e
113 ggbee = ggbe.e
114 ggbee.foo
115 ggbee.bar
116
117 var gc: GA = new GC
118 gc.e = c
119
120 #alt5#ggb.e = gc.as(GB)
121 #alt5#ggbe = ggb.e
122 #alt5#ggbee = ggbe.e
123 #alt5#ggbee.foo
124 #alt5#ggbee.bar
125
126 #alt6#gga.e = gc
127 #alt6#ggbe = ggb.e
128 #alt6#ggbee = ggbe.e
129 #alt6#ggbee.foo
130 #alt6#ggbee.bar
131
132 var ga2: GA = new GA
133 ga2.e = b
134
135 #alt7#ggb.e = ga2.as(GB)
136 #alt7#ggbe = ggb.e
137 #alt7#ggbee = ggbe.e
138 #alt7#ggbee.foo
139 #alt7#ggbee.bar
140
141 #alt8#gga.e = ga2
142 #alt8#ggbe = ggb.e
143 #alt8#ggbee = ggbe.e
144 #alt8#ggbee.foo
145 #alt8#ggbee.bar
146
147 # make the funtions live
148 if false then (new C).function_never_called
149 if false then (new C).foo