diff --git a/ets2panda/ir/statements/blockStatement.cpp b/ets2panda/ir/statements/blockStatement.cpp index 14c6f80c70edcb743a0906a8d2134248ca0ad0f4..0f0b7d01a36a7cebccda9f70599564a8e8b42468 100644 --- a/ets2panda/ir/statements/blockStatement.cpp +++ b/ets2panda/ir/statements/blockStatement.cpp @@ -34,6 +34,20 @@ void BlockStatement::TransformChildren(const NodeTransformer &cb, std::string_vi } } +AstNode *BlockStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + ArenaVector statements(allocator->Adapter()); + + for (auto *statement : this->statements_) { + statements.push_back(statement->Clone(allocator, parent)->AsStatement()); + } + + auto retVal = util::NodeAllocator::ForceSetParent(allocator, allocator, std::move(statements)); + retVal->SetParent(parent); + + return retVal; +} + void BlockStatement::Iterate(const NodeTraverser &cb) const { // This will survive pushing element to the back of statements_ in the process diff --git a/ets2panda/ir/statements/blockStatement.h b/ets2panda/ir/statements/blockStatement.h index 04fe521c868a6ac7a88b56cbff006414eef8a3af..94627554c0c95e6c776526507f929da5b4a67854 100644 --- a/ets2panda/ir/statements/blockStatement.h +++ b/ets2panda/ir/statements/blockStatement.h @@ -72,6 +72,8 @@ public: void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; + AstNode *Clone(ArenaAllocator *const allocator, AstNode *const parent) override; + void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; diff --git a/ets2panda/test/runtime/ets/17926.ets b/ets2panda/test/runtime/ets/17926.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e55c289cbf682153ff1ff2043e237dcc2c0139b --- /dev/null +++ b/ets2panda/test/runtime/ets/17926.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 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. + */ + +function foo(...args: Object[]): void { + let fnc : () => void = args[0] as () => void + fnc() +} + +let global = 0 + +let l1 = () : void => { global += 1 } +foo(l1) +assert(global == 1) +foo(() : void => { global += 2 }) +assert(global == 3) + +function main() { +}