syntax: 'meth' -> 'fun', 'attr' -> 'var'
[nit.git] / tests / base_attr_isset.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 fun output is intern
24 fun +(o: Int): Int is intern
25 end
26
27 universal Bool
28 fun output is intern
29 end
30
31 class Integer
32 readable writable var _val: Int
33 init(val: Int) do _val = val
34 fun output do _val.output
35 end
36
37 class Foo
38 var _a1: Integer
39 readable var _a2: Integer
40 fun run
41 do
42 _a1.output
43 a2.output
44 end
45
46 fun show(i: Int)
47 do
48 i.output
49 (isset _a1).output
50 (isset _a2).output
51 end
52
53 init
54 do
55 show(1)
56 _a1 = new Integer(1)
57 show(2)
58 _a2 = new Integer(_a1.val + 1)
59 show(3)
60 end
61
62 init nop do end
63 end
64
65 class Bar
66 special Foo
67 var _a3: Integer#!alt1# #!alt2#
68 #alt1#var _a3: Integer = new Integer(9000)
69 #alt2#var _a3: nullable Integer
70 redef fun run
71 do
72 _a1.output
73 _a2.output
74 _a3.output
75 end
76
77 redef fun show(i)
78 do
79 super
80 (isset _a3).output
81 end
82
83 init
84 do
85 nop
86 show(4)
87 _a1 = new Integer(10)
88 show(5)
89 _a2 = new Integer(20)
90 show(6)
91 _a3 = new Integer(30)
92 show(7)
93 end
94 end
95
96 var f = new Foo
97 var b = new Bar
98 f.run
99 b.run