Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_new_factory.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 core::kernel
16
17 interface A
18 new do return new B(5)
19 end
20
21 class B
22 super A
23 var i: Int
24 redef fun output do
25 'B'.output
26 i.output
27 end
28 end
29
30 interface G[E: Object]
31 new(a: E) do return new H[E](a)
32 fun dup:G[E] is abstract
33 end
34
35 class H[F: Object]
36 super G[F]
37 var o: F
38
39 redef fun output do
40 'H'.output
41 o.output
42 end
43
44 redef fun dup do return new G[F](self.o)
45 end
46
47 var b = new B(1)
48 b.output
49 var a = new A
50 a.output
51
52 var ha = new H[A](a)
53 ha.output
54 var hb = new H[B](b)
55 hb.output
56
57 var ga = new G[A](a)
58 ga.output
59 var gb = new G[B](b)
60 gb.output
61
62 ga.dup.output
63 gb.dup.output
64
65 var gga = new G[G[A]](ga)
66 gga.output
67 var ggb = new G[G[B]](gb)
68 ggb.output
69
70 gga.dup.output
71 ggb.dup.output