Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_ffi_c_polymorphism.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
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 extern class NativeA
18 new `{ return NULL; `}
19 fun foo do print "a"
20 end
21
22 extern class NativeB
23 super NativeA
24 new `{ return NULL; `}
25 redef fun foo do print "b"
26 end
27
28 extern class NativeC
29 super NativeA
30 new `{ return NULL; `}
31 redef fun foo do print "c"
32 end
33
34 class A
35 type NATIVE: NativeA
36 var native: NATIVE
37 end
38
39 class B
40 super A
41 redef type NATIVE: NativeB
42 end
43
44 class C
45 super A
46 redef type NATIVE: NativeC
47 end
48
49 for a in [new A(new NativeA), new B(new NativeB), new C(new NativeC)] do
50 a.native.foo
51 end
52
53 var a = new A(new NativeA)
54 var b = new A(new NativeB)
55 var c = new B(new NativeB)
56 #alt1# var d = new B(new NativeA)
57 a.native = new NativeB
58 #alt2# c.native = new NativeA