update NOTICE and LICENSE
[nit.git] / tests / test_variance_param.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 class A
18 type T: A
19 type U: B
20 fun foo(a: T) do a.out
21 fun bar(b: U) do b.out
22 fun baz(i: C) do i.out
23 fun out do 'A'.output
24
25 init do end
26 end
27
28 class B
29 super A
30 redef type T: B
31 redef type U: C
32 redef fun foo(a: T) do a.out
33 redef fun bar(b: U) do b.out
34 redef fun baz(i: C) do i.out
35 redef fun out do 'B'.output
36
37 init do end
38 end
39
40 class C
41 super B
42 redef type T: C
43 redef fun foo(a: T) do a.out
44 redef fun bar(b: U) do b.out
45 redef fun output do i.output
46 redef fun out
47 do
48 var i: Object = self
49 if i isa C then
50 i.output
51 else
52 'X'.output
53 end
54 end
55 var i: Int
56 init (i:Int) do self.i = i
57 end
58 var a = new A
59 var b = new B
60 var ab: A = b
61 var i = new C(5)
62 var ai: A = i
63 var bi: B = i
64
65 a.foo(a)
66 a.foo(b)
67 a.foo(i)
68 a.bar(b)
69 a.bar(i)
70 a.baz(i)
71 #alt1#ab.foo(a) # covariant
72 ab.foo(b)
73 ab.foo(i)
74 #alt2#ab.bar(b) # covariant
75 ab.bar(i)
76 ab.baz(i)
77 #alt3#ai.foo(a) # covariant
78 #alt4#ai.foo(b) # covariant
79 ai.foo(i)
80 #alt5#ai.bar(b) # covariant
81 ai.bar(i)
82 ai.baz(i)
83
84 b.foo(b)
85 b.foo(i)
86 b.bar(i)
87 b.baz(i)
88 #alt6#bi.foo(b) # covariant
89 bi.foo(i)
90 bi.bar(i)
91 bi.baz(i)
92
93 i.foo(i)
94 i.bar(i)
95 i.baz(i)