Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_ft_detect_variance_constraints.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 # Test classes for variance analysis
15
16 import end
17
18 interface Object
19 end
20
21 # covariant
22 class A[T]
23 fun foo: T is abstract
24 end
25
26 # contravariant
27 class B[T]
28 fun foo(t: T) is abstract
29 end
30
31 # invariant
32 class C[T]
33 fun foo(t: T) is abstract
34
35 fun bar: T is abstract
36 end
37
38 # bivariant
39 class D[T]
40 fun foo(x: Object) is abstract
41 end
42
43 # bivariant, the contravariant position of this complex expression
44 # reverse the variance, but contra*bivar = bivar
45 class E[T]
46 super D[T]
47
48 fun bar(x: E[D[C[T]]]) is abstract
49 end
50
51 # Covariant, the contravariant position reverse the variance,
52 # and the variance of A[B[T]] is contravariance
53 class F[T]
54 super D[T]
55
56 fun bar(x: A[B[T]]) is abstract
57 end
58
59 # Can be annotated bivariant
60 class G[T]
61 super D[T]
62
63 fun bar: A[D[E[T]]] is abstract
64 end
65
66 # invariant
67 class H[T]
68 fun bar: A[B[C[T]]] is abstract
69 end
70
71 # Bivariant
72 class Src[T]
73 fun bar (x: Dest[T]) is abstract
74 end
75
76 # Bivariant
77 class Dest[T]
78 fun bar (x: Src[T]) is abstract
79 end
80
81 # Contravariant
82 class Src2[T]
83 super B[T]
84
85 fun bar(x: Src[B[T]]) is abstract
86 end
87
88 # Bivariant
89 class Cycle2[T]
90 fun foo(x: Cycle2[T]): Cycle2[T] is abstract
91 end
92
93 # Bivariant
94 class Cycle3[T]
95 fun foo(x: Cycle2[T]): C[D[T]] is abstract
96 end