diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 534203ded5bac9a87d4b97ff82fd894fedc66d40..26ed0287658a54c18ba8c4e87ec46c68a05e9ac5 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1606,6 +1606,10 @@ bool ETSChecker::ResolveLambdaArgumentType(Signature *signature, ir::Expression bool ETSChecker::TrailingLambdaTypeInference(Signature *signature, const ArenaVector &arguments) { ES2PANDA_ASSERT(arguments.back()->IsArrowFunctionExpression()); + if (signature->Params().empty()) { + LogError(diagnostic::NO_SUCH_SIG_WITH_TRAILING_LAMBDA, {}, arguments.front()->Parent()->Start()); + return false; + } const size_t lastParamPos = signature->GetSignatureInfo()->params.size() - 1; const size_t lastArgPos = arguments.size() - 1; // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) diff --git a/ets2panda/test/ast/parser/ets/trailing_lambda_neg.ets b/ets2panda/test/ast/parser/ets/trailing_lambda_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..212b342bda82e2c900ec8dbe797db7a0d535606b --- /dev/null +++ b/ets2panda/test/ast/parser/ets/trailing_lambda_neg.ets @@ -0,0 +1,34 @@ +/* + * 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 Animal { + name: string; + speak(): void { + console.log(d${this.name} make a noise.`); + } +} + +/* @@? 19:9 Error TypeError: No matching call signature with trailing lambda */ +/* @@? 19:21 Error TypeError: Unresolved reference d$ */ +/* @@? 19:23 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 19:35 Error SyntaxError: Unexpected token 'make'. */ +/* @@? 19:35 Error TypeError: Unresolved reference make */ +/* @@? 19:40 Error SyntaxError: Unexpected token 'a'. */ +/* @@? 19:40 Error TypeError: Unresolved reference a */ +/* @@? 19:42 Error SyntaxError: Unexpected token 'noise'. */ +/* @@? 19:42 Error TypeError: Unresolved reference noise */ +/* @@? 19:48 Error SyntaxError: Identifier expected. */ +/* @@? 19:48 Error SyntaxError: Identifier expected, got '`'. */ +/* @@? 19:49 Error SyntaxError: Unexpected token ')'. */