First NIT release and new clean mercurial repository
[nit.git] / tests / test_gen_inh.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 import kernel
18
19 class Gen1[E, F]
20 special Object
21 readable writable attr _e: E
22 attr _f_: F
23 meth f: F do return _f_ end
24 meth f=(x: F) do _f_ = x end
25
26 init do end
27 end
28
29 class Gen2[G: Int]
30 special Gen1[G, Char]
31
32 init do end
33 end
34
35 class Gen3[H: Int]
36 special Gen1[H, Char]
37 redef readable redef writable redef attr _e: H
38 redef attr _f_: Char
39 redef meth f: Char do return _f_ end
40 redef meth f=(x: Char) do _f_ = x end
41
42 init do end
43 end
44
45 var g1 = new Gen1[Int, Char]
46 var g2 = new Gen2[Int]
47 var g3 = new Gen3[Int]
48 g1.e = 1
49 g1.f = '1'
50 g2.e = 2
51 g2.f = '2'
52 g3.e = 3
53 g3.f = '3'
54
55 g1.f.output
56 g1.e.output
57 g2.f.output
58 g2.e.output
59 g3.f.output
60 g3.e.output
61
62 g1 = g2
63 g1.f.output
64 g1.e.output
65
66 g1 = g3
67 g1.f.output
68 g1.e.output