From abde97b26d21b2e01e36e475f2557a78d4a6cda6 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 Https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/icvuii?from=project-issue 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 ab87ed9b46..32042f6b99 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -3283,6 +3283,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