From 43a67fe6e225b1d6d11f8c43e2a3c0401293dfc4 Mon Sep 17 00:00:00 2001 From: Mingyang Date: Thu, 24 Jul 2025 14:21:34 +0800 Subject: [PATCH] Fix Missing MemberExpression Object TsType Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICOGQ5 Reason: The compiler crashed in `unboxLowering` due to `mexpr->Object()->TsType()` being null, specifically when accessing enum members in annotation default values like: @interface A { field: MyEnum = MyEnum.Value1 } The type checker skipped type resolution for the `object` part of `MemberExpression` under certain conditions, causing a null dereference in UnboxLowering. Description: In `ETSAnalyzer::Check(ir::MemberExpression *expr)`, if `expr->TsType()` is not `nullptr`, it will directly `return expr->TsType()` and leave `Object()->TsType()` as `nullptr`. Therefore, in `ETSAnalyzer.cpp:3095 ProcessRequiredFields`, clone's TsType should be cleaned by `clone->CleanCheckInformation()`. Tests: ninja tests passed tests/tests-u-runner/runner.sh --ets-cts --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-func-tests --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --astchecker --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-runtime --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --parser --no-js --show-progress --build-dir x64.release --processes=all passed Signed-off-by: Mingyang --- ets2panda/checker/ETSAnalyzer.cpp | 1 + ...otation_MemberExpression_Object_TsType.ets | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ets2panda/test/runtime/ets/Annotation_MemberExpression_Object_TsType.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 74631ae976..07aa29ff7d 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -3102,6 +3102,7 @@ static void ProcessRequiredFields(ArenaUnorderedMapClone(checker->Allocator(), st); + clone->CleanCheckInformation(); st->AddProperty(clone); clone->Check(checker); } diff --git a/ets2panda/test/runtime/ets/Annotation_MemberExpression_Object_TsType.ets b/ets2panda/test/runtime/ets/Annotation_MemberExpression_Object_TsType.ets new file mode 100644 index 0000000000..d1ec3fc071 --- /dev/null +++ b/ets2panda/test/runtime/ets/Annotation_MemberExpression_Object_TsType.ets @@ -0,0 +1,27 @@ +/* + * 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. + */ + +namespace MyNamespace { + export enum MyEnum { + EnumField1 = 0, + EnumField2 = 1 + } +} +@interface ClassAnnotation { + field: MyNamespace.MyEnum = MyNamespace.MyEnum.EnumField1; +} +@ClassAnnotation +class MyClass { +} -- Gitee