From db172df622b02012590ee262a8f047a27188ed04 Mon Sep 17 00:00:00 2001 From: Anna Antipina Date: Tue, 9 Jan 2024 15:47:43 +0300 Subject: [PATCH] Title: fix Array generic constructor with union Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8UVS7 Description: fix the assertion in the function that creates nullish type so that it works for Unions Test: ${ARK_SOURCE_DIR}/tests/tests-u-runner/runner.sh ${ARK_SOURCE_DIR} --ets-runtime --build-dir="${ARK_BUILD_DIR}" --heap-verifier="fail_on_verification:pre:into:before_g1_concurrent:post" --timeout=30 --force-generate --test-file generic_constructor_with_union.ets Signed-off-by: Anna Antipina --- .../checker/types/ets/etsTypeParameter.cpp | 3 +-- .../ets/generic_constructor_with_union.ets | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/runtime/ets/generic_constructor_with_union.ets diff --git a/ets2panda/checker/types/ets/etsTypeParameter.cpp b/ets2panda/checker/types/ets/etsTypeParameter.cpp index d19a6ef116..f747631ae6 100644 --- a/ets2panda/checker/types/ets/etsTypeParameter.cpp +++ b/ets2panda/checker/types/ets/etsTypeParameter.cpp @@ -144,8 +144,7 @@ Type *ETSTypeParameter::Substitute(TypeRelation *relation, const Substitution *s if (this != original && ((ContainsNull() && !repl_type->ContainsNull()) || (ContainsUndefined() && !repl_type->ContainsUndefined()))) { // this type is explicitly marked as nullish - ASSERT(repl_type->IsETSObjectType() || repl_type->IsETSArrayType() || repl_type->IsETSFunctionType() || - repl_type->IsETSTypeParameter()); + ASSERT(ETSChecker::IsReferenceType(repl_type)); auto nullish_flags = TypeFlag(TypeFlags() & TypeFlag::NULLISH); auto *new_repl_type = checker->CreateNullishType(repl_type, nullish_flags, checker->Allocator(), relation, checker->GetGlobalTypesHolder()); diff --git a/ets2panda/test/runtime/ets/generic_constructor_with_union.ets b/ets2panda/test/runtime/ets/generic_constructor_with_union.ets new file mode 100644 index 0000000000..4ec5964d82 --- /dev/null +++ b/ets2panda/test/runtime/ets/generic_constructor_with_union.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 main(): void { + let x = new Array<(Number|String)>(); +} \ No newline at end of file -- Gitee