diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 4bf8a2f7c12e504a9444cd6f11cb62e1de1d65c8..3652998750bf0b72f4ac5ac64ba670b0724eeec6 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -1436,7 +1436,7 @@ ETSChecker *ETSObjectType::GetETSChecker() void ETSObjectType::CheckAndInstantiateProperties() const { - auto *checker = relation_->GetChecker()->AsETSChecker(); + [[maybe_unused]] auto *checker = relation_->GetChecker()->AsETSChecker(); auto *declNode = GetDeclNode(); if (HasObjectFlag(ETSObjectFlags::BUILTIN_TYPE) && declNode == nullptr) { declNode = SuperType()->GetDeclNode(); @@ -1445,11 +1445,6 @@ void ETSObjectType::CheckAndInstantiateProperties() const ES2PANDA_ASSERT(checker->IsAnyError()); return; } - - TypeStackElement tse {checker, this, {{diagnostic::CYCLIC_INHERITANCE, {this->Name()}}}, declNode->Start()}; - if (tse.HasTypeError()) { - return; - } InstantiateProperties(); } @@ -1463,7 +1458,7 @@ void ETSObjectType::InstantiateProperties() const return; } - ES2PANDA_ASSERT(!propertiesInstantiated_); + ES2PANDA_ASSERT(!propertiesInstantiated_ && declNode_ != nullptr); declNode_->Check(checker); auto subst = effectiveSubstitution_ == nullptr diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 2491ba33fda5854c1505dce6e970fb93a687accb..909e33fa5c307babc688c417ceff9de83f76a832 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -208,6 +208,11 @@ checker::Type *ETSTypeReferencePart::HandleInternalTypes(checker::ETSChecker *co if (name->IsIdentifier()) { variable = ident->Variable(); } else { + checker::TypeStackElement tse { + checker, this, {{diagnostic::CIRCULAR_DEPENDENCY, {GetIdent()->Name()}}}, Start()}; + if (tse.HasTypeError()) { + return checker->GlobalTypeError(); + } if (name->AsTSQualifiedName()->Left()->Variable() != nullptr && name->AsTSQualifiedName()->Left()->Variable()->TsType() != nullptr && name->AsTSQualifiedName()->Left()->Variable()->TsType()->IsETSObjectType()) { diff --git a/ets2panda/test/ast/compiler/ets/circular_inheritance_parameter.ets b/ets2panda/test/ast/compiler/ets/circular_inheritance_parameter.ets index 467fc6d5c7b25403cb1a3d5aa68cbb05d1a27778..cb99d022d2899b769eac1a7b0d2e94c349e1380e 100644 --- a/ets2panda/test/ast/compiler/ets/circular_inheritance_parameter.ets +++ b/ets2panda/test/ast/compiler/ets/circular_inheritance_parameter.ets @@ -17,5 +17,5 @@ class D{ f7(x: string, y: D.f7){} } -/* @@? 16:8 Error TypeError: Cyclic inheritance involving D. */ +/* @@? 17:20 Error TypeError: Circular dependency detected for identifier: f7 */ /* @@? 17:22 Error TypeError: 'f7' type does not exist. */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_self/export.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_self/export.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ef41650a3fc73fecd9b179620bd5d4c1af8d13f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_self/export.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. + */ + +import {C, I} from "./import_self" + +export function foo(){} + +export class A implements I { + onTest(p: C){ + console.log(p.name) + } +} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_self/import_self.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_self/import_self.ets new file mode 100644 index 0000000000000000000000000000000000000000..b205b73bec02b32ee9633dbd7001593a772fa004 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_self/import_self.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. + */ + +import * as File from "./import_self" + +export class C { + name: string = "123" + constructor() { } +} + +export interface I { + onTest(p: File.C) +} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_self/test.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_self/test.ets new file mode 100644 index 0000000000000000000000000000000000000000..11da459b9b8a1f55dadd39b69390d1b46c43a901 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_self/test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import {foo, A} from "./export" + +function main(){ + new A().onTest({name: "12345"}) +} \ No newline at end of file