From db5c91c30e1142d0cfc0c2664c07048461f134e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=AE=B6=E7=86=99?= Date: Tue, 24 Jun 2025 15:53:14 +0800 Subject: [PATCH] Fix es2panda compile crash in AliasParam MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 梁家熙 --- ets2panda/checker/ets/helpers.cpp | 9 ++++-- .../ast/parser/ets/lambda_param_array.ets | 31 +++++++++++++++++++ .../test/runtime/ets/AliasParameters.ets | 22 +++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/lambda_param_array.ets create mode 100644 ets2panda/test/runtime/ets/AliasParameters.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 8be037eadd..4c9982ba6e 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1494,8 +1494,9 @@ static void CollectAliasParametersForBoxing(Type *expandedAliasType, std::setIsETSObjectType()) { auto objectType = expandedAliasType->AsETSObjectType(); - needToBeBoxed = - objectType->GetDeclNode()->IsClassDefinition() || objectType->GetDeclNode()->IsTSInterfaceDeclaration(); + auto objectTypeNode = objectType->GetDeclNode(); + needToBeBoxed = objectTypeNode != nullptr && + (objectTypeNode->IsClassDefinition() || objectTypeNode->IsTSInterfaceDeclaration()); for (const auto typeArgument : objectType->TypeArguments()) { CollectAliasParametersForBoxing(typeArgument, parametersNeedToBeBoxed, needToBeBoxed); } @@ -2508,6 +2509,10 @@ void ETSChecker::InferTypesForLambda(ir::ScriptFunction *lambda, Signature *sign { ES2PANDA_ASSERT(signature->Params().size() >= lambda->Params().size()); for (size_t i = 0; i < lambda->Params().size(); ++i) { + if (!lambda->Params().at(i)->IsETSParameterExpression()) { + LogError(diagnostic::NO_SUCH_SIG_WITH_TRAILING_LAMBDA, {}, lambda->Params().at(i)->Start()); + return; + } auto *const lambdaParam = lambda->Params().at(i)->AsETSParameterExpression()->Ident(); if (lambdaParam->TypeAnnotation() == nullptr) { lambdaParam->Variable()->SetTsType(signature->Params().at(i)->TsType()); diff --git a/ets2panda/test/ast/parser/ets/lambda_param_array.ets b/ets2panda/test/ast/parser/ets/lambda_param_array.ets new file mode 100644 index 0000000000..51caba27ab --- /dev/null +++ b/ets2panda/test/ast/parser/ets/lambda_param_array.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +interface ResizeObserverEntry {} +class ResizeObserver { + constructor(callback: (entries: ResizeObserverEntry[]) => void) {} + disconnect(): void {} + observe(target: Element): void {} + unobserve(target: Element): void {} +} + +const resizeObserver = new ResizeObserver(([entry]) => { + // Dummy usage +}); + +/* @@? 20:21 Error TypeError: Cannot find type 'Element'. */ +/* @@? 21:23 Error TypeError: Cannot find type 'Element'. */ +/* @@? 24:43 Error TypeError: No matching call signature with trailing lambda */ +/* @@? 24:53 Error SyntaxError: Unexpected token '=>'. */ diff --git a/ets2panda/test/runtime/ets/AliasParameters.ets b/ets2panda/test/runtime/ets/AliasParameters.ets new file mode 100644 index 0000000000..150c81994a --- /dev/null +++ b/ets2panda/test/runtime/ets/AliasParameters.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. + */ + +type ValueAlias = Record<"val", V>; + +declare function value(val: V): ValueAlias; + +function main() { + assertTrue(true) +} -- Gitee