diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 8be037eadd49d0a7fd4015ab2fc46536df8a43ac..94aa9345fa5936d9d8b295815e1ed0018111047d 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); } @@ -2480,6 +2481,10 @@ void ETSChecker::InferTypesForLambda(ir::ScriptFunction *lambda, ir::ETSFunction Signature *maybeSubstitutedFunctionSig) { 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) { // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) @@ -2508,6 +2513,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 0000000000000000000000000000000000000000..51caba27abf97084ffc6ab6b63855e8d21b8e5ff --- /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 '=>'. */