From 1d0154b50a460f62239f724fc039ad738cfeeb04 Mon Sep 17 00:00:00 2001 From: ekkoruse Date: Tue, 29 Jul 2025 16:17:00 +0800 Subject: [PATCH] fix never in restargs fix never in restargs Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICPKC3?from=project-issue Signed-off-by: ekkoruse --- ets2panda/checker/ETSAnalyzer.cpp | 2 +- ets2panda/checker/ets/function.cpp | 3 ++- ets2panda/test/ast/parser/ets/rest_never.ets | 24 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/rest_never.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index db0b14f554..aeb614a3d1 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -415,7 +415,7 @@ checker::Type *ETSAnalyzer::Check(ir::SpreadElement *expr) const return expr->SetTsType(exprType->AsETSObjectType()->TypeArguments().front()); } - if (!exprType->IsETSArrayType() && !exprType->IsETSTupleType()) { + if (!exprType->IsETSArrayType() && !exprType->IsETSTupleType() && !exprType->IsETSReadonlyArrayType()) { if (!exprType->IsTypeError()) { // Don't duplicate error messages for the same error checker->LogError(diagnostic::SPREAD_OF_INVALID_TYPE, {exprType}, expr->Start()); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 317fc2afcb..8e9b17cc2d 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -619,7 +619,8 @@ bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const Ar // backing out of check that results in a signature mismatch would be difficult // so only attempt it if there is only one candidate signature restArgument->SetPreferredType(targetType); - auto const argumentType = restArgument->Check(this); + argument->Check(this); + auto const argumentType = restArgument->TsType(); auto const invocationCtx = checker::InvocationContext( Relation(), restArgument, argumentType, substitutedSig->RestVar()->TsType(), argument->Start(), diff --git a/ets2panda/test/ast/parser/ets/rest_never.ets b/ets2panda/test/ast/parser/ets/rest_never.ets new file mode 100644 index 0000000000..dd17382ea1 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/rest_never.ets @@ -0,0 +1,24 @@ +/* +* 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 low 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 sum(...nums: number[]) { +} + +function main() { + sum(...null!) +} + +/* @@? 20:9 Error TypeError: Spread expression can be applied only to array or tuple type, but 'never' is provided */ +/* @@? 20:12 Warning Warning: Bad operand type, the operand of the non-nullish expression is 'null' or 'undefined'. */ \ No newline at end of file -- Gitee