diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index a0b9b4bc75618998fdd1a2e4458ec2d6796d4965..e65917414723fcabbe37783c1cbf3675617f9424 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 0000000000000000000000000000000000000000..7efcf9dae74656ff500e05127f946d4527555754 --- /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 '}'. */