First NIT release and new clean mercurial repository
[nit.git] / tests / test_variance_ret.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 class A
18 meth foo: A
19 do
20 return new A
21 end
22
23 meth bar: B
24 do
25 return new B
26 end
27
28 meth baz: Int
29 do
30 return 5
31 end
32
33 redef meth output
34 do
35 'A'.output
36 end
37
38 init do end
39 end
40
41 class B
42 special A
43 redef meth foo: B
44 do
45 return new B
46 end
47 redef meth bar: Int
48 do
49 return 6
50 end
51 redef meth baz: Int
52 do
53 return 7
54 end
55 redef meth output
56 do
57 'B'.output
58 end
59
60 init do end
61 end
62
63 redef class Int
64 special B
65 redef meth foo: Int
66 do
67 return 8
68 end
69 redef meth bar: Int
70 do
71 return 9
72 end
73 redef meth output is intern
74 end
75
76 var a = new A
77 var b = new B
78 var ab: A = b
79 var i = 5
80 var ai: A = i
81 var bi: B = i
82
83 a.foo.output
84 a.bar.output
85 a.baz.output
86
87 ab.foo.output
88 ab.bar.output
89 ab.baz.output
90
91 ai.foo.output
92 ai.bar.output
93 ai.baz.output
94
95 b.foo.output
96 b.bar.output
97 b.baz.output
98
99 bi.foo.output
100 bi.bar.output
101 bi.baz.output
102
103 i.foo.output
104 i.bar.output
105 i.baz.output