From d92697448d2ff8dc782167de0ad02656cf9f347d Mon Sep 17 00:00:00 2001 From: yp9522 Date: Thu, 24 Jul 2025 15:57:35 +0800 Subject: [PATCH] Gettype Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICOJS8 Signed-off-by: yp9522 --- ets2panda/ir/ets/etsUnionType.cpp | 4 ++- ets2panda/test/ast/compiler/ets/getType.ets | 27 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/getType.ets diff --git a/ets2panda/ir/ets/etsUnionType.cpp b/ets2panda/ir/ets/etsUnionType.cpp index 0a74affb97..d987a6b8e4 100644 --- a/ets2panda/ir/ets/etsUnionType.cpp +++ b/ets2panda/ir/ets/etsUnionType.cpp @@ -98,7 +98,9 @@ checker::Type *ETSUnionType::GetType(checker::ETSChecker *checker) ArenaVector types(checker->Allocator()->Adapter()); for (auto *it : Types()) { - types.push_back(it->GetType(checker)); + if (auto *type = it->GetType(checker)) { + types.push_back(type); + } } checker->Relation()->SetNode(this); diff --git a/ets2panda/test/ast/compiler/ets/getType.ets b/ets2panda/test/ast/compiler/ets/getType.ets new file mode 100644 index 0000000000..aee120c32a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/getType.ets @@ -0,0 +1,27 @@ +/* + * 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: * + * 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. + */ + +declare type type_tuple_union = [string, boolean, number] | (this.mnum === other.mnum && this.mden === other.mden +)[] + +/* @@? 15:62 Error SyntaxError: A 'this' type is available only as return type in a non-static method of a class or struct and extension functions. */ +/* @@? 15:66 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 15:67 Error TypeError: Unresolved reference mnum */ +/* @@? 15:76 Error TypeError: Unresolved reference other */ +/* @@? 15:90 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 15:95 Error TypeError: Property 'mden' does not exist on type 'Error' */ +/* @@? 16:1 Error SyntaxError: Unexpected token ')'. */ +/* @@? 16:1 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@? 16:3 Error SyntaxError: Unexpected token ']'. */ +/* @@? 27:67 Error SyntaxError: Unexpected token, expected ']'. */ \ No newline at end of file -- Gitee