From 01a9dd0f8a2c8901f73c4192c8d0fc83fd27d830 Mon Sep 17 00:00:00 2001 From: xuxinjie4 Date: Fri, 11 Jul 2025 11:33:09 +0800 Subject: [PATCH] Fix crash with forupdatestmt Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/pulls/6967 Signed-off-by: xuxinjie4 --- ets2panda/ir/statements/forUpdateStatement.cpp | 6 +++--- .../test/ast/compiler/ets/forupdatestmt.ets | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/forupdatestmt.ets diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 912dd11f40..123bb71a20 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -127,9 +127,9 @@ checker::VerifiedType ForUpdateStatement::Check(checker::ETSChecker *checker) ForUpdateStatement *ForUpdateStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const init = init_->Clone(allocator, nullptr); - auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); - auto *const update = update_->Clone(allocator, nullptr)->AsExpression(); + auto *const init = init_ == nullptr ? nullptr : init_->Clone(allocator, nullptr); + auto *const test = test_ == nullptr ? nullptr : test_->Clone(allocator, nullptr)->AsExpression(); + auto *const update = update_ == nullptr ? nullptr : update_->Clone(allocator, nullptr)->AsExpression(); auto *const body = body_->Clone(allocator, nullptr)->AsStatement(); auto *const clone = util::NodeAllocator::ForceSetParent(allocator, init, test, update, body); diff --git a/ets2panda/test/ast/compiler/ets/forupdatestmt.ets b/ets2panda/test/ast/compiler/ets/forupdatestmt.ets new file mode 100644 index 0000000000..03d8cd8dd5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/forupdatestmt.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +let a = ()=>{ + for(;;){} // should compile +} -- Gitee