- // zweic - test program for method typing
- // M. Ganguin, J. Ruffin 2005
-
- class foo {}
- class bar extends foo {}
- class baz extends bar {}
-
- // Method
-
- class MethodTest {
- UNKNOWN foo() {} // 1/5 failure of clause 1 (incorrectly typed return type)
-
- Null bar(Int a, Null b, UNKNOWN c) {} // 2/5 failure of clause 1 (incorrectly typed arguments)
-
- MethodTest classReturnTest() { // success of clause 2 (containing class as return type)
- return this
- }
-
- bar overrideTest(bar a, bar b) { return new bar() } // success of clause 3
-
- foo overrideTest(bar a, bar b) { // 3/5 failure of clauses 3 and 4 (return type not subtype of bar)
- return new bar()
- }
-
- bar overrideTest(baz a, bar b) { // 4/5 failure of clauses 3 and 4 (parameter type not supertype of bar)
- return new bar()
- }
-
- baz overrideTest(foo a, foo b) { // successful override
- return new baz() // success (polymorphism)
- }
-
- Null varScopeTest(Int a, foo f) {
- Int b = a; // success of clause 6 (parameter in variable scope)
- foo g = f; // success of clause 6 (parameter in variable scope)
- MethodTest m = this; // success of clause 6 (this in variable scope)
- }
-
- bar returnExpressionTypeTest() { return new foo() } // 5/5 failure of clause 7 (expression type not subtype of declared return type)
-
- bar returnExpressionTypeTest2() { return new baz() } // success of clause 7
-
- }
-
- 0