From ba55dc166a0c9df7867442d7ad01df242b15f7cf Mon Sep 17 00:00:00 2001 From: yp9522 Date: Wed, 25 Jun 2025 17:39:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E7=88=B6=E7=B1=BB=E6=88=96?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=A7=81=E6=9C=89=E6=96=B9=E6=B3=95=E6=8A=A5?= =?UTF-8?q?CTE=201=20Issue:=20https://gitee.com/openharmony/arkcompiler=5F?= =?UTF-8?q?ets=5Ffrontend/issues/ICHSCY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yp9522 --- .../compiler/ets/override_private_method.ets | 39 +++++++++++++++ .../runtime/ets/override_private_method.ets | 47 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/override_private_method.ets create mode 100644 ets2panda/test/runtime/ets/override_private_method.ets diff --git a/ets2panda/test/ast/compiler/ets/override_private_method.ets b/ets2panda/test/ast/compiler/ets/override_private_method.ets new file mode 100644 index 0000000000..c34126e906 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/override_private_method.ets @@ -0,0 +1,39 @@ +/* + * 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. + */ + +class Base { + public public_member() {} + protected protected_member() {} + private private_member() {} +} + +class Derived extends Base { + public override public_member() {} + protected override protected_member() {} + private override private_member/* @@ label */() {} +} + +interface Interface { + public_member(); + private private_member() {} +} + +class Derived2 implements Interface { + public override public_member() {} + private override private_member/* @@ label1 */() {} +} + +/* @@@ label Error TypeError: Method private_member(): void in Derived not overriding any method */ +/* @@@ label1 Error TypeError: Method private_member(): void in Derived2 not overriding any method */ diff --git a/ets2panda/test/runtime/ets/override_private_method.ets b/ets2panda/test/runtime/ets/override_private_method.ets new file mode 100644 index 0000000000..b32cf69ae8 --- /dev/null +++ b/ets2panda/test/runtime/ets/override_private_method.ets @@ -0,0 +1,47 @@ +/* + * 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. + */ + +class Base { + public public_member(): int { + return 10; + } + protected protected_member(): int { + return 20; + } + private private_member(): int { // Subclasses can't override parent's private member + return 30; + } +} + +interface Interface { + public_member(): int; + private private_member(): int {} +} + +class Derived extends Base implements Interface{ + public override public_member(): int { + return 1; + } + protected override protected_member(): int { + return 2; + } +} + +function main() { + let base : Base = new Base(); + let derived : Derived = new Derived(); + assertEQ(base.public_member(), 10); + assertEQ(derived.public_member(), 1); +} -- Gitee