From 809f65f6636a5a29c13acd57020c8db1958992ff Mon Sep 17 00:00:00 2001 From: wangzhengji Date: Wed, 30 Jul 2025 16:19:17 +0800 Subject: [PATCH] Fix union method with record with getter crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICPUB8 Signed-off-by: wangzhengji --- ets2panda/checker/ETSAnalyzer.cpp | 3 ++ .../compiler/ets/record_with_getter_crash.ets | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/record_with_getter_crash.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index e20d9d56bdc..52e342363da 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2080,6 +2080,9 @@ static void SetTypeforRecordProperties(const ir::ObjectExpression *expr, checker recordPropertyExpr = recordProperty->AsProperty()->Value(); } else if (recordProperty->IsSpreadElement()) { recordPropertyExpr = recordProperty->AsSpreadElement()->Argument(); + } else if (recordProperty->IsIdentifier() && recordProperty->AsIdentifier()->IsErrorPlaceHolder()) { + ES2PANDA_ASSERT(checker->IsAnyError()); + continue; } else { ES2PANDA_UNREACHABLE(); } diff --git a/ets2panda/test/ast/compiler/ets/record_with_getter_crash.ets b/ets2panda/test/ast/compiler/ets/record_with_getter_crash.ets new file mode 100644 index 00000000000..a0daa879158 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/record_with_getter_crash.ets @@ -0,0 +1,49 @@ +/* + * 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. + */ + +interface I { + meth(): Record +} +interface J { + meth(): Record +} + +class A implements I { + meth(): Record { + return { + get a(): number { + return 11.0 + } + } + } +} + +class B implements J { + meth(): Record { + return { 'b': 22.0} + } +} + +let u1: I | J = new A() +let u2: I | J = new B() + +function main() { + assertEQ(u1.meth()['a'], 11.0) + assertEQ(u2.meth()['b'], 22.0) +} + +/* @@? 26:17 Error SyntaxError: Object pattern can't contain methods. */ +/* @@? 43:5 Error TypeError: Unresolved reference assertEQ */ +/* @@? 44:5 Error TypeError: This expression is not callable. */ -- Gitee