From d73736898560b0ec82726cfad6b1a1a0bc50482c Mon Sep 17 00:00:00 2001 From: yp9522 Date: Wed, 16 Jul 2025 11:35:49 +0800 Subject: [PATCH] Fixisvalidrestargumentnullpoint Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMHZC Signed-off-by: yp9522 --- ets2panda/checker/ets/function.cpp | 3 +- .../ast/compiler/ets/IsValidRestArgument.ets | 29 +++++++++++++++++++ 2 files changed, 31 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 fd2d36b35f..f8dffc69af 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -513,7 +513,8 @@ bool ETSChecker::IsValidRestArgument(ir::Expression *const argument, Signature * const TypeRelationFlag flags, const std::size_t index) { auto *restParamType = substitutedSig->RestVar()->TsType(); - if (argument->IsObjectExpression()) { + if (argument->IsObjectExpression() && + (restParamType->IsTypeError() || restParamType->IsETSArrayType() || restParamType->IsETSResizableArrayType())) { argument->SetPreferredType(GetElementTypeOfArray(restParamType)); // 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 0000000000..5f974ed79e --- /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