diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index fd2d36b35fd451063f215c921ccb2d27627c3726..0e6d3518242e35f9dd5ae93f80c38ea9a99b0947 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -374,7 +374,7 @@ Signature *ETSChecker::ValidateParameterlessConstructor(Signature *signature, co // #22952: remove optional arrow leftovers bool ETSChecker::CheckOptionalLambdaFunction(ir::Expression *argument, Signature *substitutedSig, std::size_t index) { - if (argument->IsArrowFunctionExpression()) { + if (argument->IsArrowFunctionExpression() && substitutedSig->HasFunction()) { auto *const arrowFuncExpr = argument->AsArrowFunctionExpression(); if (ir::ScriptFunction *const lambda = arrowFuncExpr->Function(); diff --git a/ets2panda/test/ast/compiler/ets/test_error_type.ets b/ets2panda/test/ast/compiler/ets/test_error_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..36a920fbf73b09b0dff6c7ae79b9681e7e9bd2c0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/test_error_type.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +type itfun = (() => void) | (() => Promise) | ((done: () => void) => void); +let hy = (desc: string, in: int, func: itfun) => { + return "a"; +} + +function test() { + hy("aaa", 15, (): => void { + let a = "big"; + }); +} + +/* @@? 22:5 Error TypeError: No matching call signature for ("aaa", Int, () => *ERROR_TYPE*) */ +/* @@? 22:19 Error TypeError: Type '() => *ERROR_TYPE*' is not compatible with type '() => Promise|(done: () => void) => void' at index 3 */ +/* @@? 22:23 Error SyntaxError: Invalid Type. */ +/* @@? 22:26 Error SyntaxError: Unexpected token 'void'. */ +/* @@? 22:31 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 24:6 Error SyntaxError: Unexpected token ')'. */