From 28dea84191a8927471ce1da6c54e6b45724424cf Mon Sep 17 00:00:00 2001 From: tengtengh Date: Sat, 26 Jul 2025 17:05:51 +0800 Subject: [PATCH] Fix es2panda abort (ResolveLambdaArgumentType) Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICP04E Signed-off-by: tengtengh --- ets2panda/checker/ets/typeCheckingHelpers.cpp | 3 ++ .../ets/constantExpressionLowering.cpp | 4 +++ .../ets/nagative_trailingLambda_abort.ets | 35 +++++++++++++++++++ ets2panda/util/path.cpp | 3 +- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/nagative_trailingLambda_abort.ets diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 534203ded5..345bd6ce97 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1605,6 +1605,9 @@ bool ETSChecker::ResolveLambdaArgumentType(Signature *signature, ir::Expression bool ETSChecker::TrailingLambdaTypeInference(Signature *signature, const ArenaVector &arguments) { + if (arguments.empty() || signature->GetSignatureInfo()->params.empty()) { + return false; + } ES2PANDA_ASSERT(arguments.back()->IsArrowFunctionExpression()); const size_t lastParamPos = signature->GetSignatureInfo()->params.size() - 1; const size_t lastArgPos = arguments.size() - 1; diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index d70dd6580e..72f3279a03 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -18,6 +18,7 @@ #include #include "checker/ETSchecker.h" +#include "checker/types/typeError.h" #include "compiler/lowering/util.h" #include "ir/expressions/literals/undefinedLiteral.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" @@ -1395,6 +1396,9 @@ ir::AstNode *ConstantExpressionLowering::Fold(ir::AstNode *constantNode) if (node->IsBinaryExpression()) { auto binop = node->AsBinaryExpression(); if (IsSupportedLiteral(binop->Left()) && IsSupportedLiteral(binop->Right())) { + ERROR_SANITY_CHECK(context_->diagnosticEngine, + binop->OperatorType() != lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING, + return node); return FoldBinaryExpression(binop, context_); } } diff --git a/ets2panda/test/ast/compiler/ets/nagative_trailingLambda_abort.ets b/ets2panda/test/ast/compiler/ets/nagative_trailingLambda_abort.ets new file mode 100644 index 0000000000..ff97814945 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/nagative_trailingLambda_abort.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +*22Array() { + let callback = (arrElem: JSValue) => { + if (arrElem as string !== expectedArr[idx]) {} + console.log(`fasdfasdfafd:`); + console.log(`arrElem = ${arrElem}, expectedArr[${idx}] = ${expan xxxxse istribumptyArr agreed ) + itations undeectedArr[idx]}`); + result = false; + return; + } + result = true; + idx++; + 222222??222.27?22dXX2222 + +/* @@? 16:1 Error SyntaxError: Unexpected token '*'. */ +/* @@? 16:2 Error SyntaxError: Unexpected token '22'. */ +/* @@? 16:4 Error SyntaxError: Unexpected token 'Array'. */ +/* @@? 20:74 Error SyntaxError: Expected '}', got 'identification literal'. */ +/* @@? 27:22 Error SyntaxError: Unexpected token. */ +/* @@? 36:1 Error SyntaxError: Expected '}', got 'end of stream'. */ + diff --git a/ets2panda/util/path.cpp b/ets2panda/util/path.cpp index ad902018c6..b47a24962f 100644 --- a/ets2panda/util/path.cpp +++ b/ets2panda/util/path.cpp @@ -76,7 +76,8 @@ void Path::InitializeFileName() } size_t extensionPosition = fileNameWithExtension_.Mutf8().find_last_of('.'); - fileName_ = fileNameWithExtension_.Substr(0, extensionPosition); + fileName_ = extensionPosition == std::string::npos ? fileNameWithExtension_ + : fileNameWithExtension_.Substr(0, extensionPosition); } void Path::InitializeFileNameWithExtension() -- Gitee