diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 6c0bc3f2ef5042855a853172920554c49e9a2da8..716f65e4b265689381f6f4d0dc745543106a8068 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 0000000000000000000000000000000000000000..a0a65edf47dc84a2349095ad711a68459f59cfa2 --- /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 '}'. */