update NOTICE and LICENSE
[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 redef writable = 30
28 redef var baz: Int redef writable = 40
29 end
30
31 class C
32 super B
33 redef fun foo: Int do return 100
34 redef fun bar=(i: Int) do i.output
35 redef fun baz: Int do return 400
36 redef fun baz=(i: Int) do i.output
37 end
38
39 var a = new A
40 #alt1#a.foo = 1
41 a.foo.output
42 a.bar = 2
43 #alt2#a.bar.output
44 a.baz = 3
45 a.baz.output
46
47 '\n'.output
48
49 var b = new B
50 b.foo = 10
51 b.foo.output
52 b.bar = 20
53 b.bar.output
54 b.baz = 30
55 b.baz.output
56
57 '\n'.output
58
59 var c = new C
60 c.foo = 100
61 c.foo.output
62 c.bar = 200
63 c.bar.output
64 c.baz = 300
65 c.baz.output