From 5bda19c493aabaf02481e82bba498dd3cda69719 Mon Sep 17 00:00:00 2001 From: zmw Date: Mon, 14 Jul 2025 14:58:46 +0800 Subject: [PATCH] Fix conflict call union type crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICM4J2 Description: Fix confilict call union type crash Signed-off-by: zmw Change-Id: Ie93c43ecb14f27d0fc8e6e2bfb298d815458cf40 --- ets2panda/ir/expressions/memberExpression.cpp | 7 +++- .../method_call_confilict_in_union_types.ets | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/method_call_confilict_in_union_types.ets diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 6c0bc3f2ef..716f65e4b2 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -233,7 +233,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/method_call_confilict_in_union_types.ets b/ets2panda/test/ast/compiler/ets/method_call_confilict_in_union_types.ets new file mode 100644 index 0000000000..a0a65edf47 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/method_call_confilict_in_union_types.ets @@ -0,0 +1,42 @@ +/* + * 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 under the licenses { } + foo(v: int): void {} +} + +class B { + foo(v: string): void { } +} + +function foo(x: A | B) { + x.foo("123") +} + +/* @@? 17:8 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:14 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:18 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:27 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:28 Error SyntaxError: Unexpected token '{'. */ +/* @@? 18:9 Error TypeError: Unresolved reference v */ +/* @@? 18:10 Error SyntaxError: Unexpected token ':'. */ +/* @@? 18:10 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 18:12 Error SyntaxError: Unexpected token 'int'. */ +/* @@? 18:15 Error SyntaxError: Unexpected token ')'. */ +/* @@? 18:16 Error SyntaxError: Unexpected token ':'. */ +/* @@? 18:18 Error SyntaxError: Unexpected token 'void'. */ +/* @@? 18:23 Error SyntaxError: Unexpected token '{'. */ +/* @@? 19:1 Error SyntaxError: Unexpected token '}'. */ -- Gitee