compile: implicit isset for attribute read access
[nit.git] / tests / base_attr_nullable.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 end
18
19 interface Object
20 end
21
22 universal Int
23 meth output is intern
24 meth +(o: Int): Int is intern
25 end
26
27 class Integer
28 readable writable attr _val: Int
29 init(val: Int) do _val = val
30 meth output do _val.output
31 end
32
33 class Foo
34 attr _a1: Integer
35 readable attr _a2: Integer
36 meth run
37 do
38 _a1.output
39 a2.output
40 end
41
42 meth run_other(o: Foo)
43 do
44 o._a1.output
45 o._a2.output
46 end
47
48 init
49 do
50 #alt1#run
51 _a1 = new Integer(1)
52 #alt2#run
53 _a2 = new Integer(_a1.val + 1)
54 end
55
56 init nop do end
57 end
58
59 class Bar
60 special Foo
61 attr _a3: Integer
62 redef meth run
63 do
64 _a1.output
65 _a2.output
66 _a3.output
67 end
68
69 init
70 do
71 nop
72 #alt3#run
73 _a1 = new Integer(10)
74 #alt4#run_other(self)
75 _a2 = new Integer(20)
76 #alt5#run
77 _a3 = new Integer(30)
78 end
79 end
80
81 var f = new Foo
82 var b = new Bar
83 f.run
84 b.run