015d483179fbc54738f81666848a6dad1fd1b4c8
[nit.git] / tests / contracts_inheritance.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 # Check usage of contract on a diamond inheritance
16
17 class ArrayInt
18 super Array[Int]
19
20 fun toto(e: Int)
21 do
22 print "toto ArrayInt"
23 end
24 end
25
26
27 class MyArrayInt
28 super ArrayInt
29
30 redef fun toto(e)
31 is
32 ensures(e == 12)
33 do
34 print "toto MyArrayInt"
35 super e
36 end
37 end
38
39 class MyArrayInt2
40 super ArrayInt
41
42 redef fun toto(e)
43 is
44 ensures(e == 11)
45 do
46 print "toto MyArrayInt2"
47 super e
48 print "Good"
49 end
50 end
51
52 class MySubArray
53 super MyArrayInt
54 super MyArrayInt2
55 end
56
57 var test = new MySubArray
58 test.toto(11)# fail contract on MyArrayInt define e == 12