diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index f4048ebd6fee8ee42d1095630f6b38831b14d672..84fbf811859576d20f61125f0b2e1b9bf1700192 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -805,6 +805,12 @@ bool ETSChecker::IsAllowedTypeAliasRecursion(const ir::TSTypeAliasDeclaration *t return true; }; + if (typeAliasNode->TypeAnnotation()->IsETSFunctionType() && + typeAliasNode->TypeAnnotation()->AsETSFunctionType()->ReturnType()->IsETSTypeReference()) { + isAllowedRerursiveType &= typeAliasDeclarationCheck( + typeAliasNode->TypeAnnotation()->AsETSFunctionType()->ReturnType()->AsETSTypeReference()->Part()); + } + if (typeAliasNode->TypeAnnotation()->IsETSTypeReference()) { isAllowedRerursiveType &= typeAliasDeclarationCheck(typeAliasNode->TypeAnnotation()->AsETSTypeReference()->Part()); diff --git a/ets2panda/test/ast/compiler/ets/type-alias-recursion.ets b/ets2panda/test/ast/compiler/ets/type-alias-recursion.ets new file mode 100644 index 0000000000000000000000000000000000000000..5199a8d86f8bd56f501eca01f21e13507370712d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/type-alias-recursion.ets @@ -0,0 +1,24 @@ +/* + * 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 foo = () => bar; +type bar = () => foo; + +function baz() : bar { + return baz; +} + +/* @@? 17:1 Error TypeError: Circular type alias reference */ +/* @@? 20:10 Error TypeError: Type '() => () => () => *ERROR_TYPE*' is not compatible with the enclosing method's return type '() => () => *ERROR_TYPE*' */ diff --git a/ets2panda/test/ast/compiler/ets/typealias_as_value.ets b/ets2panda/test/ast/compiler/ets/typealias_as_value.ets index e6f3bb13a735fddfbc53d9b1ef91d04416d4b067..ee3c8bcf858cb5350db7f748d5a22b7ad198ea9a 100644 --- a/ets2panda/test/ast/compiler/ets/typealias_as_value.ets +++ b/ets2panda/test/ast/compiler/ets/typealias_as_value.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -type RF = (p:RF) => RF +type RF = (p:string) => number function main(){ let v1 = () => {return RF}