update NOTICE and LICENSE
[nit.git] / tests / base_virtual_type_check.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 class A
17 type T: K
18 type U: T
19 fun check(o: Object)
20 do
21 o.output
22 '<'.output
23 'T'.output
24 (o isa T).output
25 o.output
26 '<'.output
27 'U'.output
28 (o isa U).output
29 end
30 fun check2(o: T)
31 do
32 o.output
33 '<'.output
34 'T'.output
35 '\n'.output
36 end
37 fun check3(o: U)
38 do
39 o.output
40 '<'.output
41 'U'.output
42 '\n'.output
43 end
44 end
45 class B
46 super A
47 redef type T: L
48 end
49 class J
50 redef fun output do 'J'.output
51 end
52 class K
53 super J
54 redef fun output do 'K'.output
55 end
56 class L
57 super K
58 redef fun output do 'L'.output
59 end
60
61 var a = new A
62 a.check(new J)
63 a.check(new K)
64 a.check(new L)
65 #alt1#a.check2(new J) # Static error
66 a.check2(new K)
67 a.check2(new L)
68 #alt2#a.check3(new J) # Static error
69 a.check3(new K)
70 a.check3(new L)
71 var b = new B
72 b.check(new J)
73 b.check(new K)
74 b.check(new L)
75 #alt3#b.check2(new J) # Static error
76 #alt4#b.check2(new K) # Static error
77 b.check2(new L)
78 #alt5#b.check3(new J) # Static error
79 #alt6#b.check3(new K) # Static error
80 b.check3(new L)
81 var ab: A = new B
82 ab.check(new J)
83 ab.check(new K)
84 ab.check(new L)
85 #alt7#ab.check2(new J) # Static error
86 #alt8#ab.check2(new K) # Dynamic error
87 ab.check2(new L)
88 #alt9#ab.check3(new J) # Static error
89 #alt10#ab.check3(new K) # Dynamic error
90 ab.check3(new L)