From 7b393601ba4977e445d4970fec4f051533a36ab2 Mon Sep 17 00:00:00 2001 From: daizihan Date: Sat, 19 Jul 2025 16:14:51 +0800 Subject: [PATCH] Fix fuzz crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICNEIL?from=project-issue Signed-off-by: daizihan --- ets2panda/checker/ets/typeCheckingHelpers.cpp | 2 +- ets2panda/test/runtime/ets/any_lambda.ets | 22 +++++++++++++++++++ .../test-lists/recheck/recheck-ignored.txt | 1 + ets2panda/util/helpers.cpp | 7 +++--- 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 ets2panda/test/runtime/ets/any_lambda.ets diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index bd526d218d..ae2b26c19f 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1435,7 +1435,7 @@ bool ETSChecker::CheckLambdaAssignable(ir::Expression *param, ir::ScriptFunction if (typeAnn == nullptr) { return false; } - if (typeAnn->IsETSTypeReference() && !typeAnn->AsETSTypeReference()->TsType()->IsETSArrayType()) { + if (typeAnn->IsETSTypeReference()) { typeAnn = util::Helpers::DerefETSTypeReference(typeAnn); } diff --git a/ets2panda/test/runtime/ets/any_lambda.ets b/ets2panda/test/runtime/ets/any_lambda.ets new file mode 100644 index 0000000000..0109a05033 --- /dev/null +++ b/ets2panda/test/runtime/ets/any_lambda.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +function foo(a: Any) { +} + +function main() { + foo(() => {}); + arktest.assertTrue(true); +} diff --git a/ets2panda/test/test-lists/recheck/recheck-ignored.txt b/ets2panda/test/test-lists/recheck/recheck-ignored.txt index b1dc9d23c2..b933ebac47 100644 --- a/ets2panda/test/test-lists/recheck/recheck-ignored.txt +++ b/ets2panda/test/test-lists/recheck/recheck-ignored.txt @@ -85,6 +85,7 @@ runtime/ets/lambda_with_receiver/lambda_with_receiver_trailing_in_class_method2. runtime/ets/lambda_with_receiver/lambda_with_receiver_trailing_in_function.ets runtime/ets/lambda_with_receiver/lambda_with_receiver_trailing_in_function_with_receiver.ets runtime/ets/lambda_with_receiver/lambda_with_receiver_trailing_name_duplicated.ets +runtime/ets/any_lambda.ets runtime/ets/generic_lambda_6.ets #Test that failed before CheckerPhase (on ConstantExpressionLowering) ast/parser/ets/InvalidLexer.ets diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index 37b43e97a8..86e899f655 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -819,10 +819,11 @@ ir::AstNode *Helpers::DerefETSTypeReference(ir::AstNode *node) ES2PANDA_ASSERT(node->IsETSTypeReference()); do { auto *name = node->AsETSTypeReference()->Part()->GetIdent(); - - ES2PANDA_ASSERT(name->IsIdentifier()); auto *var = name->AsIdentifier()->Variable(); - ES2PANDA_ASSERT(var != nullptr); + if (var == nullptr) { + // var == nullptr means it might be built-in type like Any type, which would cause unexpected crash below. + return node; + } auto *declNode = var->Declaration()->Node(); if (!declNode->IsTSTypeAliasDeclaration()) { return declNode; -- Gitee