From 8393c1cc1955b38f6c273d9dff4df097c27bf850 Mon Sep 17 00:00:00 2001 From: lixl9 Date: Tue, 5 Aug 2025 10:24:13 +0800 Subject: [PATCH] Fix arkconfig crashes when builtin is not set Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICR4P8 Signed-off-by: lixinglong --- ets2panda/checker/ETSchecker.cpp | 3 ++ ets2panda/checker/ets/object.cpp | 2 +- .../test-config/builtin-init/arkconfig.json | 9 ++++++ .../test-config/builtin-init/expected.json | 8 +++++ .../test-config/builtin-init/src/file_1.ets | 20 ++++++++++++ .../test-config/builtin-init/src/file_2.ets | 32 +++++++++++++++++++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/tsconfig/test-config/builtin-init/arkconfig.json create mode 100644 ets2panda/test/tsconfig/test-config/builtin-init/expected.json create mode 100644 ets2panda/test/tsconfig/test-config/builtin-init/src/file_1.ets create mode 100644 ets2panda/test/tsconfig/test-config/builtin-init/src/file_2.ets diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 3cde016475..88a71002f8 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -271,6 +271,9 @@ void ETSChecker::InitializeBuiltins(varbinder::ETSBinder *varbinder) } const auto varMap = varbinder->TopScope()->Bindings(); + if (varMap.find(compiler::Signatures::BUILTIN_OBJECT_CLASS) == varMap.end()) { + return; + } auto const objectName = InitBuiltin(this, compiler::Signatures::BUILTIN_OBJECT_CLASS); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index c09ef96952..b3af0fc6c5 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -553,7 +553,7 @@ void ETSChecker::CheckDynamicInheritanceAndImplement(ETSObjectType *const interf interfaceOrClassType->GetDeclNode()->Start()); } } - if (isFromDynamicDecl(interfaceOrClassType->SuperType())) { + if (interfaceOrClassType->SuperType() != nullptr && isFromDynamicDecl(interfaceOrClassType->SuperType())) { LogError(diagnostic::INTERFACE_OR_CLASS_CANNOT_IMPL_OR_EXTEND_DYNAMIC, {getTypeString(interfaceOrClassType), interfaceOrClassType->Name(), "extends", getTypeString(interfaceOrClassType->SuperType()), interfaceOrClassType->SuperType()->Name()}, diff --git a/ets2panda/test/tsconfig/test-config/builtin-init/arkconfig.json b/ets2panda/test/tsconfig/test-config/builtin-init/arkconfig.json new file mode 100644 index 0000000000..f8fbd7cee6 --- /dev/null +++ b/ets2panda/test/tsconfig/test-config/builtin-init/arkconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "outDir": "outdir" + }, + "files": [ + "./src/file_1.ets", + "./src/file_2.ets" + ] +} \ No newline at end of file diff --git a/ets2panda/test/tsconfig/test-config/builtin-init/expected.json b/ets2panda/test/tsconfig/test-config/builtin-init/expected.json new file mode 100644 index 0000000000..65b5812cb9 --- /dev/null +++ b/ets2panda/test/tsconfig/test-config/builtin-init/expected.json @@ -0,0 +1,8 @@ +{ + "returncode": 1, + "stdout": "Fatal error: Failed to compile from builtin-init/src/file_2.ets to builtin-init/outdir/src/file_2.abc\nFatal error: Failed to compile from builtin-init/src/file_1.ets to builtin-init/outdir/src/file_1.abc\nFatal error: Can't find prefix for 'file_1.ets' in builtin-init/arkconfig.json [file_2.ets:16:29]\nFatal error: Can't find prefix for 'file_1.ets' in builtin-init/arkconfig.json [file_2.ets:17:40]\nFatal error: Can't find prefix for 'file_1.ets' in builtin-init/arkconfig.json [file_2.ets:18:33]\nFatal error: Can't find prefix for 'file_1.ets' in builtin-init/arkconfig.json [file_2.ets:19:48]\nTypeError: Cannot find type 'Class1'. [file_2.ets:28:20]\nTypeError: Cannot find type 'Class_1'. [file_2.ets:31:20]\nFatal error: Can't find prefix for 'std/core' in builtin-init/arkconfig.json [.ets:1:15]\nFatal error: Can't find prefix for 'std/math' in builtin-init/arkconfig.json [.ets:1:40]\nFatal error: Can't find prefix for 'std/containers' in builtin-init/arkconfig.json [.ets:1:65]\nFatal error: Can't find prefix for 'std/interop/js' in builtin-init/arkconfig.json [.ets:1:96]\nFatal error: Can't find prefix for 'std/time' in builtin-init/arkconfig.json [.ets:1:127]\nFatal error: Can't find prefix for 'std/debug' in builtin-init/arkconfig.json [.ets:1:152]\nFatal error: Can't find prefix for 'std/debug/concurrency' in builtin-init/arkconfig.json [.ets:1:178]\nFatal error: Can't find prefix for 'std/testing' in builtin-init/arkconfig.json [.ets:1:216]\nFatal error: Can't find prefix for 'escompat' in builtin-init/arkconfig.json [.ets:1:244]\nFatal error: Can't find prefix for 'std/concurrency' in builtin-init/arkconfig.json [.ets:1:269]\nFatal error: Can't find prefix for 'std/annotations' in builtin-init/arkconfig.json [.ets:1:301]\nFatal error: Can't find prefix for 'std/interop' in builtin-init/arkconfig.json [.ets:1:333]", + "stderr": "" +} + + + diff --git a/ets2panda/test/tsconfig/test-config/builtin-init/src/file_1.ets b/ets2panda/test/tsconfig/test-config/builtin-init/src/file_1.ets new file mode 100644 index 0000000000..71c1a5d861 --- /dev/null +++ b/ets2panda/test/tsconfig/test-config/builtin-init/src/file_1.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. + */ + +export class Class1 { + constructor() {} +} + +export interface Interface1{} diff --git a/ets2panda/test/tsconfig/test-config/builtin-init/src/file_2.ets b/ets2panda/test/tsconfig/test-config/builtin-init/src/file_2.ets new file mode 100644 index 0000000000..70a9e88d66 --- /dev/null +++ b/ets2panda/test/tsconfig/test-config/builtin-init/src/file_2.ets @@ -0,0 +1,32 @@ +/* + * 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 type { Class1 } from 'file_1.ets'; +import type { Class1 as Class_1 } from 'file_1.ets'; +import type { Interface1 } from 'file_1.ets'; +import type { Interface1 as Interface_1 } from 'file_1.ets'; + +export class Class2 { + constructor() {} +} + +export interface Interface2 { +} + +function f1(value: Class1): void { +} + +function f2(value: Class_1): void { +} -- Gitee