Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_isa_formal_type.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
17 class A[T]
18 type U: nullable Object
19 fun testT(o: Object): Bool do return o isa T
20 fun testU(o: Object): Bool do return o isa U
21
22 fun get_c: C[U,T] do return new C[U,T]
23
24 fun testall
25 do
26 self.testT(1).output
27 self.testT(true).output
28 self.testU(1).output
29 self.testU(true).output
30 var c = get_c
31 c.testT(1).output
32 c.testT(true).output
33 c.testU(1).output
34 c.testU(true).output
35 '\n'.output
36 end
37 end
38
39 class B
40 super A[Int]
41 redef type U: Bool
42 fun foo: A[Bool] do return get_c
43 end
44
45 class C[V, W]
46 super A[V]
47 redef type U: W
48 fun foo: A[W] do return get_c
49 end
50
51 var ao = new A[Object]
52 var ai = new A[Int]
53 var b = new B
54 var coo = new C[Object, Object]
55 var cib = new C[Int, Bool]
56
57 ao.testall
58 ai.testall
59 b.testall
60 b.foo.testall
61 coo.testall
62 cib.testall
63 cib.foo.testall