diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index 644bdb35c6861e667ed1bb1c5736a11d153ffa8b..d6d7255b0aba4a661c40c27a1c4b1c2e65192268 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.cpp +++ b/ets2panda/checker/ETSAnalyzerHelpers.cpp @@ -213,7 +213,7 @@ void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::Scr checker->AddStatus(checker::CheckerStatus::IN_CONSTRUCTOR); } - if (node->IsExtensionMethod()) { + if (node->IsExtensionMethod() && scriptFunc->Signature() != nullptr) { CheckExtensionMethod(checker, scriptFunc, node); } diff --git a/ets2panda/test/ast/parser/ets/extension_function_tests/extension_function_error1.ets b/ets2panda/test/ast/parser/ets/extension_function_tests/extension_function_error1.ets new file mode 100644 index 0000000000000000000000000000000000000000..47d3887c4c2635fdf1c73651156c33eea74ed591 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/extension_function_tests/extension_function_error1.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ + +@AnimatableExtend +function animatableWidth(this: TextAttribute, this { this.width(width); return this; +} + +/* @@? 16:2 Error TypeError: Cannot find type 'AnimatableExtend'. */ +/* @@? 17:32 Error TypeError: Cannot find type 'TextAttribute'. */ +/* @@? 17:52 Error SyntaxError: The function parameter 'this' must explicitly specify the typeAnnotation. */ +/* @@? 17:52 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 17:54 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 17:59 Error TypeError: Property 'width' does not exist on type 'Error' */ diff --git a/ets2panda/test/ast/parser/ets/extension_function_tests/extension_function_error2.ets b/ets2panda/test/ast/parser/ets/extension_function_tests/extension_function_error2.ets new file mode 100644 index 0000000000000000000000000000000000000000..752a06d4cceb6598bb28c56cf9d6fa2f6c135ed4 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/extension_function_tests/extension_function_error2.ets @@ -0,0 +1,33 @@ +/* + * 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. + */ + +let a = (this: TextAttribute, this { this.width(width); return this; +} + +/* @@? 16:9 Error TypeError: 'this' cannot be referenced from a static context */ +/* @@? 16:9 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 16:9 Error TypeError: Type 'Error' cannot be assigned to type 'ETSGLOBAL' */ +/* @@? 16:14 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 16:16 Error SyntaxError: Unexpected token 'TextAttribute'. */ +/* @@? 16:16 Error TypeError: Unresolved reference TextAttribute */ +/* @@? 16:29 Error SyntaxError: Unexpected token ','. */ +/* @@? 16:31 Error SyntaxError: Unexpected token 'this'. */ +/* @@? 16:31 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 16:36 Error SyntaxError: Unexpected token '{'. */ +/* @@? 16:38 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 16:43 Error TypeError: Property 'width' does not exist on type 'Error' */ +/* @@? 16:57 Error SyntaxError: return keyword should be used in function body. */ +/* @@? 16:64 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 16:64 Error TypeError: All return statements in the function should be empty or have a value. */