diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 317fc2afcbd80ce89cacd11494ebb3b23deb6e3b..8f9b5686fa34d507ff95cd975866bd2ee2545a41 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1491,6 +1491,9 @@ checker::Type *ETSChecker::BuildMethodSignature(ir::MethodDefinition *method) auto *methodId = method->Id(); ES2PANDA_ASSERT(methodId != nullptr); ES2PANDA_ASSERT(method->Function() != nullptr); + if (methodId->AsIdentifier()->IsErrorPlaceHolder()) { + return methodId->Variable()->SetTsType(GlobalTypeError()); + } method->Function()->Id()->SetVariable(methodId->Variable()); BuildFunctionSignature(method->Function(), method->IsConstructor()); if (method->Function()->Signature() == nullptr) { diff --git a/ets2panda/test/ast/compiler/ets/arrow_function_call_as_record_property_key.ets b/ets2panda/test/ast/compiler/ets/arrow_function_call_as_record_property_key.ets index 4dc414ecae8d55007635a4f124f47655944fa159..80a265b50a267828ce0057daf79d4496e4347999 100644 --- a/ets2panda/test/ast/compiler/ets/arrow_function_call_as_record_property_key.ets +++ b/ets2panda/test/ast/compiler/ets/arrow_function_call_as_record_property_key.ets @@ -45,7 +45,7 @@ const b: Record number> = { /* @@? 23:6 Error TypeError: Indexed access is not supported for such expression type. */ /* @@? 24:20 Error TypeError: Wrong operand type for unary expression */ /* @@? 24:32 Error SyntaxError: Unexpected token ':'. */ -/* @@? 24:35 Error TypeError: Unresolved reference y */ +/* @@? 24:32 Error TypeError: This expression is not callable. */ /* @@? 24:36 Error SyntaxError: Unexpected token ':'. */ /* @@? 24:36 Error SyntaxError: Unexpected token, expected ',' or ')'. */ /* @@? 24:38 Error SyntaxError: Unexpected token 'string'. */ @@ -54,4 +54,5 @@ const b: Record number> = { /* @@? 24:45 Error SyntaxError: Unexpected token ':'. */ /* @@? 24:46 Error SyntaxError: Unexpected token 'number'. */ /* @@? 24:46 Error TypeError: The type of parameter 'number' cannot be inferred */ +/* @@? 24:56 Error TypeError: Unresolved reference y */ /* @@? 25:1 Error SyntaxError: Unexpected token '}'. */ diff --git a/ets2panda/test/ast/compiler/ets/method_error_identifier.ets b/ets2panda/test/ast/compiler/ets/method_error_identifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ccc87265748fcb23d0d70e5fcd589d70efe5b7c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/method_error_identifier.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +void function () { }; + +class BindFuncExpr { + let callback1 = function () { } + callback1 = callback1 || function () { } +} + +/* @@? 16:1 Error SyntaxError: Unexpected token 'void'. */ +/* @@? 16:6 Error SyntaxError: Unexpected token 'function'. */ +/* @@? 16:15 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 19:5 Error SyntaxError: Unexpected token 'let'. */ +/* @@? 19:21 Error SyntaxError: Function expressions are not supported, use arrow functions instead */ +/* @@? 20:5 Error TypeError: Variable 'callback1' has already been declared. */ +/* @@? 20:17 Error TypeError: Unresolved reference callback1 */ +/* @@? 20:30 Error SyntaxError: Function expressions are not supported, use arrow functions instead */ diff --git a/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets b/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets index e4ac2d35782c9a20b94cc544bb90aeb0ba88c1f0..5db33dcca04e3611534c95b28b872d732fbd7ca9 100644 --- a/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets @@ -22,7 +22,6 @@ function /* @@ label1 */(): /* @@ label2 */{ /* @@@ label Error SyntaxError: Unexpected token, expected an identifier. */ /* @@@ label1 Error SyntaxError: Unexpected token, expected an identifier. */ -/* @@@ label1 Error TypeError: Only abstract or native methods can't have body. */ /* @@@ label2 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@@ label3 Error SyntaxError: Unexpected token 'return'. */ /* @@@ label4 Error SyntaxError: Unexpected token '77'. */ diff --git a/ets2panda/test/ast/parser/ets/lambda_function_index_access_neg.ets b/ets2panda/test/ast/parser/ets/lambda_function_index_access_neg.ets index d5c80f3524b8eee43443c99f5ea8c4ddbc6c1283..ef855e4383289ea8bafca7f8b23a5ab6e6c9ae1e 100644 --- a/ets2panda/test/ast/parser/ets/lambda_function_index_access_neg.ets +++ b/ets2panda/test/ast/parser/ets/lambda_function_index_access_neg.ets @@ -20,10 +20,8 @@ let a = (... ( () => { } [] /* @@? 16:9 Error TypeError: Invalid left-hand side of assignment expression */ -/* @@? 16:9 Error TypeError: No matching call signature for *ERROR_LITERAL*(() => void) */ -/* @@? 16:9 Error TypeError: Invalid left-hand side of assignment expression */ -/* @@? 16:9 Error TypeError: No matching call signature for *ERROR_LITERAL*(() => void) */ /* @@? 16:10 Error SyntaxError: Unexpected token '...'. */ +/* @@? 16:10 Error TypeError: This expression is not callable. */ /* @@? 18:5 Error SyntaxError: Invalid left-hand side in assignment expression. */ /* @@? 18:7 Error SyntaxError: Unexpected token ':'. */ /* @@? 18:9 Error SyntaxError: Unexpected token 'async'. */