Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_safe2.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 redef class Int
16 fun foo do print self
17 end
18
19 class A
20 var x: Int
21 end
22
23 class B
24 var a: nullable A = null
25 end
26
27 class C
28 var x: Int
29 var c: nullable C = null
30 end
31
32 class D
33 var x: nullable Int
34 var d: nullable D = null
35 end
36
37 var b = new B
38
39 #alt1#b.a?.x.foo
40
41 var a = new A(10)
42
43 b.a = a
44 print "b.a.x: {b.a?.x or else "nothing"}"
45
46 var c1 = new C(1)
47 var c2 = new C(10)
48 var c3 = new C(100)
49 c1.c = c2
50 c2.c = c3
51
52 print c1.c?.c?.x or else "null"
53 print c1.c?.c?.c or else "null"
54
55 var d1 = new D(1)
56 var d2 = new D(10)
57 var d3 = new D(null)
58
59 d1.d = d2
60 d2.d = d3
61
62 print d1.d?.x or else "null"
63 print d1.d?.d?.x or else "null"