syntax: 'meth' -> 'fun', 'attr' -> 'var'
[nit.git] / tests / base_isa_cast4.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2009 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 init do end
21 end
22
23 class B
24 special A
25 fun foo(i: Int) do i.output
26 init do end
27 end
28
29 fun maybe: Bool do return true
30
31 var a: A = new B
32
33 assert a isa B
34 a.foo(1)
35 if maybe then
36 a = new A
37 else
38 a = new A
39 end
40 #alt1#a.foo(1)
41
42 a = new B
43 assert a isa B
44 a.foo(2)
45 if maybe then
46 else
47 a = new A
48 end
49 #alt2#a.foo(2)
50
51 a = new B
52 assert a isa B
53 a.foo(3)
54 if maybe then
55 a = new A
56 else
57 end
58 #alt3#a.foo(3)
59
60 a = new B
61 assert a isa B
62 a.foo(4)
63 if maybe then
64 else
65 end
66 a.foo(4)
67
68 a = new B
69 assert a isa B
70 a.foo(5)
71 if maybe then
72 a = new A
73 end
74 #alt4#a.foo(5)
75
76 a = new B
77 assert a isa B
78 a.foo(6)
79 if maybe then
80 end
81 a.foo(6)
82
83 a = new B
84 assert a isa B
85 a.foo(7)
86 while not maybe do
87 #alt5#a = new A
88 end
89 a.foo(7)
90
91 a = new B
92 assert a isa B
93 a.foo(8)
94 while not maybe do
95 end
96 a.foo(8)
97