Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_gen_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[E]
18 var e: nullable E = null
19 end
20
21 class A
22 fun foo do 1.output
23 end
24 class B
25 super A
26 redef fun foo do 2.output
27 fun bar do 20.output
28 end
29 class C
30 super A
31 redef fun foo do 3.output
32 fun function_never_called do 300.output
33 end
34
35 var b: B = new B
36 var gb: G[B] = new G[B]
37 var gbe: nullable B
38
39 gb.e = b
40 gbe = gb.e
41 gbe.foo
42 gbe.bar
43
44 var a: A = b
45
46 #alt1#gb.e = a.as(B)
47 #alt1#gbe = gb.e
48 #alt1#gbe.foo
49 #alt1#gbe.bar
50
51 var ga: G[A] = gb
52
53 ga.e = a
54 gbe = gb.e
55 gbe.foo
56 gbe.bar
57
58 var c: A = new C
59
60 #alt2#gb.e = c.as(B)
61 #alt2#gbe = gb.e
62 #alt2#gbe.foo
63 #alt3#gbe.bar
64
65 #alt3#ga.e = c
66 #alt3#gbe = gb.e
67 #alt3#gbe.foo
68 #alt3#gbe.bar
69
70 var ggb: G[G[B]] = new G[G[B]]
71 var ggbe: nullable G[B]
72 var ggbee: nullable B
73
74 ggb.e = gb
75 ggbe = ggb.e
76 ggbee = ggbe.e
77 ggbee.foo
78 ggbee.bar
79
80 #alt4#ggb.e = ga.as(G[B])
81 #alt4#ggbe = ggb.e
82 #alt4#ggbee = ggbe.e
83 #alt4#ggbee.foo
84 #alt4#ggbee.bar
85
86 var gga: G[G[A]] = ggb
87
88 gga.e = ga
89 ggbe = ggb.e
90 ggbee = ggbe.e
91 ggbee.foo
92 ggbee.bar
93
94 var gc: G[A] = new G[C]
95 gc.e = c
96
97 #alt5#ggb.e = gc.as(G[B])
98 #alt5#ggbe = ggb.e
99 #alt5#ggbee = ggbe.e
100 #alt5#ggbee.foo
101 #alt5#ggbee.bar
102
103 #alt6#gga.e = gc
104 #alt6#ggbe = ggb.e
105 #alt6#ggbee = ggbe.e
106 #alt6#ggbee.foo
107 #alt6#ggbee.bar
108
109 var ga2: G[A] = new G[A]
110 ga2.e = b
111
112 #alt7#ggb.e = ga2.as(G[B])
113 #alt7#ggbe = ggb.e
114 #alt7#ggbee = ggbe.e
115 #alt7#ggbee.foo
116 #alt7#ggbee.bar
117
118 #alt8#gga.e = ga2
119 #alt8#ggbe = ggb.e
120 #alt8#ggbee = ggbe.e
121 #alt8#ggbee.foo
122 #alt8#ggbee.bar
123
124 # make the funtions live
125 if false then (new C).function_never_called
126 if false then (new C).foo