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 0000000000000000000000000000000000000000..ef1c14d8e3be4b555f57448793e103fcef507e12 --- /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 0000000000000000000000000000000000000000..fe9ade6e628c309914510e238fa41d98375af31e --- /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 0000000000000000000000000000000000000000..21d5ff0f03a736254870f4d42011073f0fc37bf5 --- /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. */