From 8acb05c9a9f53f85b063d70fe94b4ac85e133dca Mon Sep 17 00:00:00 2001 From: Soma Simon Date: Fri, 19 Jan 2024 11:24:35 +0100 Subject: [PATCH] [ArkTS frontend] Fix call static interface method with type alias Fix condition when creating the searchflag, to find the property Fixed internal issue #14507 Change-Id: Iba1ae4c08e48752f182c21bbb9c3fcc2425bf69d Signed-off-by: Soma Simon --- ets2panda/checker/ets/object.cpp | 6 ++- .../ets/call_static_with_type_alias.ets | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/runtime/ets/call_static_with_type_alias.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 22debb2259..e8a3522a90 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1180,8 +1180,10 @@ PropertySearchFlags ETSChecker::GetSearchFlags(const ir::MemberExpression *const { auto searchFlag = GetInitialSearchFlags(memberExpr); searchFlag |= PropertySearchFlags::SEARCH_IN_BASE | PropertySearchFlags::SEARCH_IN_INTERFACES; - - if (targetRef != nullptr && targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { + if (targetRef != nullptr && + (targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE) || + (targetRef->HasFlag(varbinder::VariableFlags::TYPE_ALIAS) && + targetRef->TsType()->Variable()->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)))) { searchFlag &= ~(PropertySearchFlags::SEARCH_INSTANCE); } else if (memberExpr->Object()->IsThisExpression() || (memberExpr->Object()->IsIdentifier() && memberExpr->ObjType()->GetDeclNode() != nullptr && diff --git a/ets2panda/test/runtime/ets/call_static_with_type_alias.ets b/ets2panda/test/runtime/ets/call_static_with_type_alias.ets new file mode 100644 index 0000000000..0a86ff562a --- /dev/null +++ b/ets2panda/test/runtime/ets/call_static_with_type_alias.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 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 { + static inc(p: number): number { + return p + 1; + } +} + +class C1 { + static inc2(p: number): number { + return p + 2; + } +} + +class C2 implements I { +} + +type TI = I; +type TTI = TI; + +type TC1 = C1; +type TTC1 = TC1; + +type TC2 = C2; +type TTC2 = TC2; + +function main(): void { + assert I.inc(20) == 21; + assert TI.inc(20) == 21; + assert TTI.inc(20) == 21; + + assert C1.inc2(20) == 22; + assert TC1.inc2(20) == 22; + assert TTC1.inc2(20) == 22; + + assert C2.inc(20) == 21; + assert TC2.inc(20) == 21; + assert TTC2.inc(20) == 21; +} -- Gitee