From c517e1c9b7a1c04b7d8fc0527dfa6e23c80ab0a7 Mon Sep 17 00:00:00 2001 From: yp9522 Date: Wed, 16 Jul 2025 11:41:21 +0800 Subject: [PATCH] Fixisvalidrestargumentnullpoint Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMIEU Signed-off-by: yp9522 --- ets2panda/checker/ets/function.cpp | 4 ++- .../ast/compiler/ets/IsValidRestArgument.ets | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 ets2panda/test/ast/compiler/ets/IsValidRestArgument.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 54c1208e9a9..0da4d641056 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -491,7 +491,9 @@ bool ETSChecker::ValidateSignatureInvocationContext(Signature *substitutedSig, i bool ETSChecker::IsValidRestArgument(ir::Expression *const argument, Signature *const substitutedSig, const TypeRelationFlag flags, const std::size_t index) { - if (argument->IsObjectExpression()) { + auto *restParamType = substitutedSig->RestVar()->TsType(); + if (argument->IsObjectExpression() && + (restParamType->IsTypeError() || restParamType->IsETSArrayType() || restParamType->IsETSResizableArrayType())) { // Object literals should be checked separately afterwards after call resolution return true; } diff --git a/ets2panda/test/ast/compiler/ets/IsValidRestArgument.ets b/ets2panda/test/ast/compiler/ets/IsValidRestArgument.ets new file mode 100755 index 00000000000..5f974ed79e7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/IsValidRestArgument.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ + +class A {} +class B {} + +class C { + foo(...p: [A, B]) {} +} + +(new C()).foo({v.r2} +) + +/* @@? 23:1 Error TypeError: Expected 2 arguments, got 1. */ +/* @@? 23:1 Error TypeError: No matching call signature for foo(...) */ +/* @@? 23:15 Error TypeError: need to specify target type for class composite */ +/* @@? 23:17 Error SyntaxError: Unexpected token, expected ':'. */ -- Gitee