From 3c3066475d2b9b268794e939dbcf26b07679ae52 Mon Sep 17 00:00:00 2001 From: Mingyang Date: Thu, 17 Jul 2025 16:04:28 +0800 Subject: [PATCH] Fix Partial Type Check in RemoveUndefinedType Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICN0A6 Reason: Program will crash in RemoveUndefinedTyp, because ES2PANDA_ASSERT(type->IsETSUnionType()), where type is Partial Type Description: Add type->IsETSPartialTypeParameter to check Partial Type and avoid Assert False Tests: ninja tests passed tests/tests-u-runner/runner.sh --ets-cts --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-func-tests --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --astchecker --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-runtime --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --parser --no-js --show-progress --build-dir x64.release --processes=all passe Signed-off-by: Mingyang --- ets2panda/checker/ets/typeCheckingHelpers.cpp | 4 +++ ...rtialType_check_in_RemoveUndefinedType.ets | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/partialType_check_in_RemoveUndefinedType.ets diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 6496cdb8ce..80d51c1e97 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -157,6 +157,10 @@ Type *ETSChecker::RemoveUndefinedType(Type *const type) return type; } + if (type->IsETSPartialTypeParameter()) { + return type; + } + if (type->IsETSUndefinedType()) { return GetGlobalTypesHolder()->GlobalETSNeverType(); } diff --git a/ets2panda/test/ast/compiler/ets/partialType_check_in_RemoveUndefinedType.ets b/ets2panda/test/ast/compiler/ets/partialType_check_in_RemoveUndefinedType.ets new file mode 100644 index 0000000000..2b6557074b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/partialType_check_in_RemoveUndefinedType.ets @@ -0,0 +1,26 @@ +/* + * 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. + */ + +function genericFunc(p: Partial): void { + if (p !== undefined) { + } +} +function main() { + genericFunc<{a: number, b: string}>({a: 1}) +} + +/* @@? 21:3 Error TypeError: Bad operand type, the types of the operands must be numeric, same enumeration, or boolean type. */ +/* @@? 21:15 Error TypeError: need to specify target type for class composite */ +/* @@? 21:38 Error TypeError: need to specify target type for class composite */ -- Gitee