diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 036af5331d2ad7d343b0a64d21cb21419efc16dc..9795e917cfa4cbb40ac481f8bdeefb012dcd22ad 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -2050,26 +2050,23 @@ bool ETSChecker::CmpAssemblerTypesWithRank(Signature const *const sig1, Signatur bool ETSChecker::HasSameAssemblySignature(Signature const *const sig1, Signature const *const sig2) noexcept { - if (sig1->ArgCount() != sig2->ArgCount()) { + if (sig1->FullParamCount() != sig2->FullParamCount()) { return false; } - if (!CmpAssemblerTypesWithRank(sig1, sig2)) { - return false; - } - auto *rv1 = sig1->RestVar(); - auto *rv2 = sig2->RestVar(); - if (rv1 == nullptr && rv2 == nullptr) { - return true; - } - if (rv1 == nullptr || rv2 == nullptr) { // exactly one of them is null - return false; + auto sig1AllParamVector = sig1->FullParams(); + auto sig2AllParamVector = sig2->FullParams(); + + for (size_t ix = 0U; ix < sig1AllParamVector.size(); ++ix) { + std::stringstream s1; + std::stringstream s2; + sig1AllParamVector[ix]->TsType()->ToAssemblerTypeWithRank(s1); + sig2AllParamVector[ix]->TsType()->ToAssemblerTypeWithRank(s2); + if (s1.str() != s2.str()) { + return false; + } } - std::stringstream s1; - std::stringstream s2; - rv1->TsType()->ToAssemblerTypeWithRank(s1); - rv2->TsType()->ToAssemblerTypeWithRank(s2); - return s1.str() == s2.str(); + return true; } bool ETSChecker::HasSameAssemblySignatures(ETSFunctionType const *const func1, diff --git a/ets2panda/checker/types/signature.h b/ets2panda/checker/types/signature.h index 2a4f8ec06d417aed65fdc416c2ac9a38ee6fd543..11b478c12cea6712eb7d00e7873993eecd72ef5a 100644 --- a/ets2panda/checker/types/signature.h +++ b/ets2panda/checker/types/signature.h @@ -166,6 +166,21 @@ public: return signatureInfo_->params.size(); } + [[nodiscard]] size_t FullParamCount() const + { + return signatureInfo_->restVar == nullptr ? signatureInfo_->params.size() : signatureInfo_->params.size() + 1; + } + + [[nodiscard]] std::vector FullParams() const + { + std::vector allParamVector(signatureInfo_->params.begin(), + signatureInfo_->params.end()); + if (signatureInfo_->restVar != nullptr) { + allParamVector.push_back(signatureInfo_->restVar); + } + return allParamVector; + } + void SetReturnType(Type *type) noexcept { returnType_ = type; diff --git a/ets2panda/test/ast/compiler/ets/rest_param_has_same_assembly_test.ets b/ets2panda/test/ast/compiler/ets/rest_param_has_same_assembly_test.ets new file mode 100644 index 0000000000000000000000000000000000000000..54f00f6bb86a650dbc8c6c9a1e3da04b56ae08e9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/rest_param_has_same_assembly_test.ets @@ -0,0 +1,38 @@ +/* + * 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 { + m(a: Error, b: Object[]): int { return 1 } + /* @@ label */m(a: Error, ...b: Object[]): int { return 2 } +} + +class B { + m(a: Error, ...b: Object[]): int { return 2 } + /* @@ label1 */m(a: Error, b: Object[]): int { return 1 } +} + +class C { + m(a: Error, ...b: Object[]): int { return 1 } + /* @@ label2 */m(a: Error, b?: Object[]): int { return 2 } +} + +class D { + m(a: Error, b: Object[]): int { return 1 } + /* @@ label3 */m(a: Error, b?: Object[]): int { return 2 } +} +/* @@@ label Error TypeError: Function m with this assembly signature already declared. */ +/* @@@ label1 Error TypeError: Function m with this assembly signature already declared. */ +/* @@@ label2 Error TypeError: Function m with this assembly signature already declared. */ +/* @@@ label3 Error TypeError: Function m with this assembly signature already declared. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets b/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets index 6db1b894cc10500bbd017da658a4a6b5d9b4544a..0ffeab8bc1b93bf702a9d77d15842797fc9bd87b 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets @@ -205,6 +205,7 @@ function main(): void { /* @@? 52:12 Error TypeError: Unresolved reference q */ /* @@? 52:12 Error TypeError: All return statements in the function should be empty or have a value. */ /* @@? 52:23 Error TypeError: Unresolved reference p */ +/* @@? 55:1 Error TypeError: Function foo with this assembly signature already declared. */ /* @@? 55:26 Error SyntaxError: Rest parameter should be either array or tuple type. */ /* @@? 59:23 Error SyntaxError: Rest parameter should be either array or tuple type. */ /* @@? 63:26 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ @@ -284,4 +285,4 @@ function main(): void { /* @@? 165:5 Error TypeError: This expression is not callable. */ /* @@? 166:5 Error TypeError: Expected 1 arguments, got 0. */ /* @@? 166:5 Error TypeError: No matching call signature */ -/* @@? 288:1 Error SyntaxError: Expected '}', got 'eos'. */ +/* @@? 289:1 Error SyntaxError: Expected '}', got 'eos'. */ diff --git a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets index d938d892ff459d4fe1fe567faecb0eb969151f06..135df246b00f74cd180a49cdfc3958d5f05d3250 100644 --- a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets @@ -203,6 +203,7 @@ function main(): void { /* @@? 52:12 Error TypeError: Unresolved reference q */ /* @@? 52:12 Error TypeError: All return statements in the function should be empty or have a value. */ /* @@? 52:23 Error TypeError: Unresolved reference p */ +/* @@? 55:1 Error TypeError: Function foo with this assembly signature already declared. */ /* @@? 55:26 Error SyntaxError: Rest parameter should be either array or tuple type. */ /* @@? 59:23 Error SyntaxError: Rest parameter should be either array or tuple type. */ /* @@? 63:26 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ @@ -282,4 +283,4 @@ function main(): void { /* @@? 165:5 Error TypeError: This expression is not callable. */ /* @@? 166:5 Error TypeError: Expected 1 arguments, got 0. */ /* @@? 166:5 Error TypeError: No matching call signature */ -/* @@? 286:1 Error SyntaxError: Expected '}', got 'eos'. */ +/* @@? 287:1 Error SyntaxError: Expected '}', got 'eos'. */