Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_attr_lazy_nullable.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 Foo
18 var a1: nullable Object = fa1 is lazy
19 var a2: nullable Object = fa2 is lazy
20 fun fa1: nullable Object do
21 1.output
22 return 10
23 end
24 fun fa2: nullable Object do
25 2.output
26 return 20
27 end
28 end
29
30 fun o(o: nullable Object)
31 do
32 if o == null then
33 'n'.output
34 '\n'.output
35 else
36 o.output
37 end
38 end
39
40 var f = new Foo
41 o f.a1
42 o f.a1
43 o f.a2
44 o f.a2
45 '\n'.output
46
47 var g = new Foo
48 o g.a2
49 o g.a1
50 o g.a2
51 o g.a1
52 '\n'.output
53
54 var h = new Foo
55 h.a1 = 100
56 h.a1.output
57 h.a1.output