From d23cf69fbb8379155bbf87b67d254b5e1c703e27 Mon Sep 17 00:00:00 2001 From: zengzengran Date: Thu, 31 Jul 2025 17:31:50 +0800 Subject: [PATCH] Fix constant expression lowering crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICQ5YD Description: ConstantExpressionLowering involves unfolding some identifiers into constant expressions. For member expressions, the case where property is not an identifier should be intercepted. Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran # --- .../ets/constantExpressionLowering.cpp | 4 ++++ .../ets/constantExpressionLowering_2.ets | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/constantExpressionLowering_2.ets diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index b4e2564600..c9fdaf1357 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -1213,6 +1213,10 @@ static varbinder::Variable *ResolveMemberExpressionProperty(ir::MemberExpression return nullptr; } + if (!me->Property()->IsIdentifier()) { + return nullptr; + } + auto option = varbinder::ResolveBindingOptions::STATIC_DECLARATION | varbinder::ResolveBindingOptions::STATIC_VARIABLES; return scope->FindLocal(me->Property()->AsIdentifier()->Name(), option); diff --git a/ets2panda/test/ast/compiler/ets/constantExpressionLowering_2.ets b/ets2panda/test/ast/compiler/ets/constantExpressionLowering_2.ets new file mode 100644 index 0000000000..3a2315963a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/constantExpressionLowering_2.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. + */ + +enum CCCCCCCCC {} + +CCCCCCCCC[foo()].foo(); + +/* @@? 18:11 Error TypeError: Unresolved reference foo */ +/* @@? 18:18 Error TypeError: Property 'foo' does not exist on type 'String' */ -- Gitee