diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index db0b14f5547accc17033ee1b0b560c0629804620..aeb614a3d12007e913433e0f2959af360973d6ae 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 317fc2afcbd80ce89cacd11494ebb3b23deb6e3b..8e9b17cc2d4f949e7b6ce2197cf045aa2ff8e61c 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 0000000000000000000000000000000000000000..dd17382ea1f90f1d379b532f9dd9097708c6ef38 --- /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