diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 912dd11f40e02c16def7bf72aa490607a2a316e2..123bb71a20230ed00cb93088fae122b8e7661299 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/parser/ets/forupdate_clone.ets b/ets2panda/test/ast/parser/ets/forupdate_clone.ets new file mode 100644 index 0000000000000000000000000000000000000000..231d72c0e6aa05524403eafe8cbae390eb6b0ced --- /dev/null +++ b/ets2panda/test/ast/parser/ets/forupdate_clone.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024-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 b = (() => { + return () => { + let a = 1 + for (let i = 0; i < 5;) { + a += 1 + i += 1 + } + return a; + }; +})();