diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index a0b9b4bc75618998fdd1a2e4458ec2d6796d4965..64dcba1f6e54a5ef8230165344da7d2ec16b9ffd 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -223,6 +223,10 @@ checker::Type *MemberExpression::TraverseUnionMember(checker::ETSChecker *checke }; for (auto *const type : unionType->ConstituentTypes()) { + if (commonPropType != nullptr && commonPropType->IsTypeError()) { + break; + } + auto *const apparent = checker->GetApparentType(type); ES2PANDA_ASSERT(apparent != nullptr); if (apparent->IsETSObjectType()) { 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..700814cac4b50cff794710f6ad6b90c0ca9273ff --- /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:9 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:15 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:19 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:28 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 '}'. */