syntax: 'meth' -> 'fun', 'attr' -> 'var'
[nit.git] / tests / base_as_notnull.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2005-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 kernel
18
19 class A
20 var _i: Int
21 redef fun output do _i.output
22 init(i: Int) do _i = i
23 end
24
25 class B
26 special A
27 end
28
29 fun outa(a: A) do a.output
30 fun outb(b: B) do b.output
31
32 var a: A = new A(1)
33 var ab: A = new B(2)
34 var b: B = new B(3)
35 var na: nullable A = new A(4)
36 var nab: nullable A = new B(5)
37 var nb: nullable B = new B(6)
38 var nan: nullable A = null
39 var nbn: nullable B = null
40
41 outa(a.as(not null))
42 outa(ab.as(not null))
43 outa(b.as(not null))
44 outa(na.as(not null))
45 outa(nab.as(not null))
46 outa(nb.as(not null))
47
48 '\n'.output
49
50 #alt1#outb(a.as(not null))
51 #alt2#outb(ab.as(not null))
52 outb(b.as(not null))
53 #alt3#outb(na.as(not null))
54 #alt4#outb(nab.as(not null))
55 outb(nb.as(not null))
56
57 '\n'.output
58
59 #alt5#nan.as(not null).output
60 #alt6#nbn.as(not null).output
61 #alt7#null.as(not null).output