diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 901e786d7c94af2b3f429c17f246c58c7a3331bb..a950291522bf723634b5ed875d6ed9dee420af4c 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -571,6 +571,9 @@ bool ETSChecker::IsValidRestArgument(ir::Expression *const argument, Signature * const TypeRelationFlag flags, const std::size_t index) { auto *restParamType = substitutedSig->RestVar()->TsType(); + if (restParamType->IsETSTupleType()) { + return false; + } if (argument->IsObjectExpression()) { argument->SetPreferredType(GetElementTypeOfArray(restParamType)); // Object literals should be checked separately afterwards after call resolution @@ -585,9 +588,6 @@ bool ETSChecker::IsValidRestArgument(ir::Expression *const argument, Signature * } const auto argumentType = argument->Check(this); - if (restParamType->IsETSTupleType()) { - return false; - } if (argument->HasAstNodeFlags(ir::AstNodeFlags::RESIZABLE_REST)) { 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 0000000000000000000000000000000000000000..f5bc78e6d615240a3622f2d826156ced55b26ee5 --- /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 ':'. */