Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_as_notnull2.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 G[E]
18 fun foo(e: E): E
19 do
20 var ee = e.as(not null)
21 ee.output
22 return ee
23 end
24 end
25
26 class A
27 super G[Object]
28 redef fun foo(e)
29 do
30 var ee = e.as(not null)
31 ee.output
32 return ee
33 end
34 end
35
36 class B[F: Object]
37 super G[nullable F]
38 redef fun foo(e)
39 do
40 var ee = e.as(not null)
41 ee.output
42 return ee
43 end
44 end
45
46 class C[F: Object]
47 super G[F]
48 redef fun foo(e)
49 do
50 var ee = e.as(not null)
51 ee.output
52 return ee
53 end
54 end
55
56 var a = new A
57 a.foo(1).output
58 #alt1#a.foo(null).output
59 var b = new B[Int]
60 b.foo(2).output
61 #alt2#b.foo(null).output
62 var c = new C[Int]
63 c.foo(3).output
64 #alt3#c.foo(null).output