From fa8c61c43502c3c717f2f235a6824402b90f009b Mon Sep 17 00:00:00 2001 From: fcc Date: Wed, 11 Jun 2025 17:16:10 +0800 Subject: [PATCH] fix duplicate names with builtins Avoid name conflict with builtins. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICEJG7 Signed-off-by: fcc --- ets2panda/checker/ETSchecker.cpp | 14 ++++++++------ .../ets/typealias_conflict_with_builtin.ets | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/typealias_conflict_with_builtin.ets diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index ce5dd58750..4a079d96cd 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -97,13 +97,15 @@ static util::StringView InitBuiltin(ETSChecker *checker, std::string_view signat ES2PANDA_ASSERT(iterator != varMap.end()); auto *var = iterator->second; Type *type {nullptr}; - if (var->Declaration()->Node()->IsClassDefinition()) { - type = checker->BuildBasicClassProperties(var->Declaration()->Node()->AsClassDefinition()); - } else { - ES2PANDA_ASSERT(var->Declaration()->Node()->IsTSInterfaceDeclaration()); - type = checker->BuildBasicInterfaceProperties(var->Declaration()->Node()->AsTSInterfaceDeclaration()); + if (var->HasFlag(varbinder::VariableFlags::BUILTIN_TYPE)) { + if (var->Declaration()->Node()->IsClassDefinition()) { + type = checker->BuildBasicClassProperties(var->Declaration()->Node()->AsClassDefinition()); + } else { + ES2PANDA_ASSERT(var->Declaration()->Node()->IsTSInterfaceDeclaration()); + type = checker->BuildBasicInterfaceProperties(var->Declaration()->Node()->AsTSInterfaceDeclaration()); + } + checker->GetGlobalTypesHolder()->InitializeBuiltin(iterator->first, type); } - checker->GetGlobalTypesHolder()->InitializeBuiltin(iterator->first, type); return iterator->first; } diff --git a/ets2panda/test/ast/compiler/ets/typealias_conflict_with_builtin.ets b/ets2panda/test/ast/compiler/ets/typealias_conflict_with_builtin.ets new file mode 100644 index 0000000000..80fc58e641 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/typealias_conflict_with_builtin.ets @@ -0,0 +1,18 @@ +/* + * 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 Type = int; + +/* @@? 1:3 Error TypeError: Class 'Type' is already defined with different type. */ -- Gitee