From 442b3f54990c26ef94d5d824ddc1e92258326e7f Mon Sep 17 00:00:00 2001 From: furkanocalan Date: Fri, 30 May 2025 10:43:55 +0300 Subject: [PATCH] Add and rewrite tests to cover method variance Issue: #ICBOUO Description: Added and re-written test cases to cover method variance for multiple overridde, multiple implements and default conflicts Signed-off-by: furkanocalan --- ...method_overriding_conflict_no_override.ets | 21 +++++++++++++++++ ...d_overriding_contravariant_return_type.ets | 23 +++++++++++++++++++ ...ethod_overriding_duplicate_declaration.ets | 23 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/method_overriding_conflict_no_override.ets create mode 100644 ets2panda/test/ast/compiler/ets/method_overriding_contravariant_return_type.ets create mode 100644 ets2panda/test/ast/compiler/ets/method_overriding_duplicate_declaration.ets diff --git a/ets2panda/test/ast/compiler/ets/method_overriding_conflict_no_override.ets b/ets2panda/test/ast/compiler/ets/method_overriding_conflict_no_override.ets new file mode 100644 index 0000000000..ef1c14d8e3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/method_overriding_conflict_no_override.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +interface L { foo(): string { return "L"; } } +interface R { foo(): string { return "R"; } } + +class Bad implements L, R {} + +/* @@? 19:27 Error TypeError: Method 'foo' is declared in L and R interfaces. */ diff --git a/ets2panda/test/ast/compiler/ets/method_overriding_contravariant_return_type.ets b/ets2panda/test/ast/compiler/ets/method_overriding_contravariant_return_type.ets new file mode 100644 index 0000000000..fe9ade6e62 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/method_overriding_contravariant_return_type.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +interface Base { n(): int; } + +interface BadReturn extends Base { + n(): number; +} + +/* @@? 19:4 Error TypeError: n(): double in BadReturn cannot override n(): int in Base because overriding return type is not compatible with the other return type. */ +/* @@? 19:4 Error TypeError: Method n(): double in BadReturn not overriding any method */ diff --git a/ets2panda/test/ast/compiler/ets/method_overriding_duplicate_declaration.ets b/ets2panda/test/ast/compiler/ets/method_overriding_duplicate_declaration.ets new file mode 100644 index 0000000000..21d5ff0f03 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/method_overriding_duplicate_declaration.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +interface I { foo(): void; } + +class Duplicate implements I { + foo(): void {} + foo(): void {} +} + +/* @@? 20:3 Error TypeError: Function foo is already declared. */ -- Gitee