First NIT release and new clean mercurial repository
[nit.git] / tests / test_variance_attr.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 attr _foo: Object
19 attr _bar: A
20 attr _baz: Int
21 redef meth output do 'A'.output end
22
23 init do end
24 end
25
26 class B
27 special A
28 redef attr _foo: Int
29 redef attr _bar: B
30 redef meth output do 'B'.output end
31
32 init do end
33 end
34
35 var a = new A
36 var b = new B
37 var ab: A = b
38
39 a._foo = a
40 a._foo.output
41 a._foo = b
42 a._foo.output
43 a._foo = 1
44 a._foo.output
45 a._bar = a
46 a._bar.output
47 a._bar = b
48 a._bar.output
49 a._baz = 1
50 a._baz.output
51
52 #ab._foo = a
53 #ab._foo.output
54 #ab._foo = b
55 #ab._foo.output
56 ab._foo = 1
57 ab._foo.output
58 #ab._bar = a
59 #ab._bar.output
60 ab._bar = b
61 ab._bar.output
62 ab._baz = 1
63 ab._baz.output
64
65 #b._foo = a
66 #b._foo.output
67 #b._foo = b
68 #b._foo.output
69 b._foo = 1
70 b._foo.output
71 #b._bar = a
72 #b._bar.output
73 b._bar = b
74 b._bar.output
75 b._baz = 1
76 b._baz.output
77