First NIT release and new clean mercurial repository
[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 meth foo(a: T) do a.output
21 meth bar(b: U) do b.output
22 meth baz(i: Int) do i.output
23 redef meth output do 'A'.output
24
25 init do end
26 end
27
28 class B
29 special A
30 redef type T: B
31 redef type U: Int
32 redef meth foo(a: T) do a.output
33 redef meth bar(b: U) do b.output
34 redef meth baz(i: Int) do i.output
35 redef meth output do 'B'.output
36
37 init do end
38 end
39
40 redef class Int
41 special B
42 redef type T: Int
43 redef meth foo(a: T) do a.output
44 redef meth bar(b: U) do b.output
45 redef meth output is intern
46 end
47
48 var a = new A
49 var b = new B
50 var ab: A = b
51 var i = 5
52 var ai: A = i
53 var bi: B = i
54
55 a.foo(a)
56 a.foo(b)
57 a.foo(i)
58 a.bar(b)
59 a.bar(i)
60 a.baz(i)
61 #alt1#ab.foo(a) # covariant
62 ab.foo(b)
63 ab.foo(i)
64 #alt2#ab.bar(b) # covariant
65 ab.bar(i)
66 ab.baz(i)
67 #alt3#ai.foo(a) # covariant
68 #alt4#ai.foo(b) # covariant
69 ai.foo(i)
70 #alt5#ai.bar(b) # covariant
71 ai.bar(i)
72 ai.baz(i)
73
74 b.foo(b)
75 b.foo(i)
76 b.bar(i)
77 b.baz(i)
78 #alt6#bi.foo(b) # covariant
79 bi.foo(i)
80 bi.bar(i)
81 bi.baz(i)
82
83 i.foo(i)
84 i.bar(i)
85 i.baz(i)