Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_attr4.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 A
18 fun foo: Int do return 1
19 fun bar=(i: Int) do i.output
20 fun baz: Int do return 4
21 fun baz=(i: Int) do i.output
22 end
23
24 class B
25 super A
26 redef var foo: Int = 20
27 var bar: Int = 30 is redef writable
28 redef var baz: Int = 40 is redef writable
29 end
30
31 class C
32 super B
33 redef fun foo: Int do return 100
34 redef fun bar=(i: Int) do
35 super
36 i.output
37 end
38 redef fun baz: Int do return 400
39 redef fun baz=(i: Int) do
40 super
41 i.output
42 end
43 end
44
45 var a = new A
46 #alt1#a.foo = 1
47 a.foo.output
48 a.bar = 2
49 #alt2#a.bar.output
50 a.baz = 3
51 a.baz.output
52
53 '\n'.output
54
55 var b = new B
56 b.foo = 10
57 b.foo.output
58 b.bar = 20
59 b.bar.output
60 b.baz = 30
61 b.baz.output
62
63 '\n'.output
64
65 var c = new C
66 c.foo = 100
67 c.foo.output
68 c.bar = 200
69 c.bar.output
70 c.baz = 300
71 c.baz.output