From 714732c3ec7461c6045faa418795d671dfa7d443 Mon Sep 17 00:00:00 2001 From: zmw Date: Wed, 23 Jul 2025 14:20:45 +0800 Subject: [PATCH] Fix const ident in tuple crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICO99D Description: Fix const ident in tuple crash Signed-off-by: zmw Change-Id: Ie92a354e0da6f6a42d4f4fe72373540812174157 --- .../ets/constantExpressionLowering.cpp | 4 ++++ .../const_ident_in_tuple_type_reference.ets | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/const_ident_in_tuple_type_reference.ets diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index d990bf0c27..a19564c688 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -1308,6 +1308,10 @@ ir::AstNode *ConstantExpressionLowering::MaybeUnfoldIdentifier(ir::Identifier *n return node; } + if (node->Parent()->IsETSTypeReferencePart()) { + return node; + } + auto *resolved = ResolveIdentifier(node); if (resolved == nullptr || !(resolved->Declaration()->IsConstDecl() || resolved->Declaration()->IsReadonlyDecl())) { return node; diff --git a/ets2panda/test/ast/compiler/ets/const_ident_in_tuple_type_reference.ets b/ets2panda/test/ast/compiler/ets/const_ident_in_tuple_type_reference.ets new file mode 100644 index 0000000000..1a9e72790e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/const_ident_in_tuple_type_reference.ets @@ -0,0 +1,20 @@ +/* + * 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: * + * 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. + */ + +function animations() { + let flag = false; + type Person = [flag]; +} + +/* @@? 17:20 Error TypeError: Cannot find type 'flag'. */ -- Gitee