diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index a3508bb5748d113c851e39c872215d2ef37383b1..d884fbb9964ad8775d01af4b360d558ade123a51 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1721,6 +1721,10 @@ ir::Expression *ETSParser::ParseFunctionReceiver() return AllocBrokenExpression(thisLoc); } + if (typeAnnotation->IsBrokenTypeNode()) { + return AllocBrokenExpression(thisLoc); + } + return CreateParameterThis(typeAnnotation); } diff --git a/ets2panda/test/ast/compiler/ets/function_signature_mismatch.ets b/ets2panda/test/ast/compiler/ets/function_signature_mismatch.ets new file mode 100644 index 0000000000000000000000000000000000000000..60e656cd74978369d1aae53f85b65ad2acd49cd9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/function_signature_mismatch.ets @@ -0,0 +1,36 @@ +/* + * 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. + */ + +function returnThisMember(this: { member: string }) { + return this.member; +} + +interface Container { + member: string; + returnThisMember: () => string; +} + +let container: Container; +container = { + member: "sample", + returnThisMember: returnThisMember, +}; + +function main() { + container.returnThisMember(); +} + +/* @@? 16:33 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 28:23 Error TypeError: Function name 'returnThisMember' used in the wrong context */