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