From cda73e80cb6a1766c492f27ac1b09a7365d4f381 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 22 Nov 2012 15:33:38 -0500 Subject: [PATCH] nitg-sep: workaround for covariant return type Just force to use VIRTUAL function in order to force the implementations to respond to the original signature from the introduction. More work need to be done to cleanup and simplify the stuff. Signed-off-by: Jean Privat --- tests/base_ret_covar_int.nit | 66 +++++++++++++++++++++++++++++++++ tests/sav/base_ret_covar_int.res | 20 ++++++++++ tests/sav/base_ret_covar_int_alt1.res | 1 + tests/sav/base_ret_covar_int_alt1.sav | 20 ++++++++++ 4 files changed, 107 insertions(+) create mode 100644 tests/base_ret_covar_int.nit create mode 100644 tests/sav/base_ret_covar_int.res create mode 100644 tests/sav/base_ret_covar_int_alt1.res create mode 100644 tests/sav/base_ret_covar_int_alt1.sav diff --git a/tests/base_ret_covar_int.nit b/tests/base_ret_covar_int.nit new file mode 100644 index 0000000..6681b3d --- /dev/null +++ b/tests/base_ret_covar_int.nit @@ -0,0 +1,66 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import kernel + +class A[E] + type V: Object + fun foo: Object do return 1 + + fun bar1: E do return 2 + fun bar2: E do return 3 + + fun baz1: V do return 4 + fun baz2: V do return 5 +end + +class B + super A[Int] + redef type V: Int + + redef fun foo: Int do return 11 + + redef fun bar1 do return 22 + redef fun bar2: Int do return 33 + + redef fun baz1 do return 44 + #alt1#redef fun baz2: Int do return 55 +end + +fun test_a(a: A[Object]) +do + a.foo.output + a.bar1.output + a.bar2.output + a.baz1.output + a.baz2.output +end +fun test_b(a: B) +do + a.foo.output + a.bar1.output + a.bar2.output + a.baz1.output + a.baz2.output +end + +var a = new A[Object] +test_a(a) + +a = new A[Int] +test_a(a) + +a = new B +test_a(a) +test_b(a) diff --git a/tests/sav/base_ret_covar_int.res b/tests/sav/base_ret_covar_int.res new file mode 100644 index 0000000..6d9389d --- /dev/null +++ b/tests/sav/base_ret_covar_int.res @@ -0,0 +1,20 @@ +1 +2 +3 +4 +5 +1 +2 +3 +4 +5 +11 +22 +33 +44 +5 +11 +22 +33 +44 +5 diff --git a/tests/sav/base_ret_covar_int_alt1.res b/tests/sav/base_ret_covar_int_alt1.res new file mode 100644 index 0000000..6360245 --- /dev/null +++ b/tests/sav/base_ret_covar_int_alt1.res @@ -0,0 +1 @@ +alt/base_ret_covar_int_alt1.nit:38,18--20: Redef Error: Wrong return type. found Int, expected V. diff --git a/tests/sav/base_ret_covar_int_alt1.sav b/tests/sav/base_ret_covar_int_alt1.sav new file mode 100644 index 0000000..5df0b4b --- /dev/null +++ b/tests/sav/base_ret_covar_int_alt1.sav @@ -0,0 +1,20 @@ +1 +2 +3 +4 +5 +1 +2 +3 +4 +5 +11 +22 +33 +44 +55 +11 +22 +33 +44 +55 -- 1.7.9.5