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 0000000000000000000000000000000000000000..c34126e90626f4061e1e1f34b9c7061fae0ab0a0 --- /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 0000000000000000000000000000000000000000..b32cf69ae81a5ad4017cd4f0e6b0b8094e92b3f0 --- /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); +}