From b555a2e18e38f7179154bdf4603ec085abb12afa Mon Sep 17 00:00:00 2001 From: zengzengran Date: Tue, 22 Jul 2025 20:56:32 +0800 Subject: [PATCH] Fix conflict call union type crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICO3WF Description: cherry-pick "method call confilict in union types crash" to 0603 Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran # --- ets2panda/ir/expressions/memberExpression.cpp | 7 ++- .../test/ast/compiler/ets/union_method_6.ets | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/union_method_6.ets diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index a0b9b4bc75..e659174147 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -227,7 +227,12 @@ checker::Type *MemberExpression::TraverseUnionMember(checker::ETSChecker *checke ES2PANDA_ASSERT(apparent != nullptr); if (apparent->IsETSObjectType()) { SetObjectType(apparent->AsETSObjectType()); - addPropType(ResolveObjectMember(checker).first); + auto *memberType = ResolveObjectMember(checker).first; + if (memberType != nullptr && memberType->IsTypeError()) { + return checker->GlobalTypeError(); + } + + addPropType(memberType); } else { checker->LogError(diagnostic::UNION_MEMBER_ILLEGAL_TYPE, {unionType}, Start()); } diff --git a/ets2panda/test/ast/compiler/ets/union_method_6.ets b/ets2panda/test/ast/compiler/ets/union_method_6.ets new file mode 100644 index 0000000000..7efcf9dae7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/union_method_6.ets @@ -0,0 +1,44 @@ +/* + * 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. + */ + +class A { + foo(v: string) { console.log("A:" + v) } +} + +class C { + foo)v: string) { console.log("C:" + v) } +} + +function test1(v: A|C) { + v.foo("123") +} + +/* @@? 21:8 Error SyntaxError: Unexpected token ')'. */ +/* @@? 21:8 Error SyntaxError: Field type annotation expected. */ +/* @@? 21:18 Error SyntaxError: Unexpected token ')'. */ +/* @@? 21:20 Error SyntaxError: Unexpected token '{'. */ +/* @@? 21:29 Error SyntaxError: Field type annotation expected. */ +/* @@? 21:29 Error SyntaxError: Unexpected token '.'. */ +/* @@? 21:33 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 21:34 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 21:34 Error SyntaxError: Unexpected token 'C:'. */ +/* @@? 21:34 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 21:34 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 21:39 Error SyntaxError: Unexpected token '+'. */ +/* @@? 21:41 Error TypeError: Variable 'v' has already been declared. */ +/* @@? 21:41 Error TypeError: Property 'v' must be accessed through 'this' */ +/* @@? 21:42 Error SyntaxError: Field type annotation expected. */ +/* @@? 21:42 Error SyntaxError: Unexpected token ')'. */ +/* @@? 22:1 Error SyntaxError: Unexpected token '}'. */ -- Gitee