1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 14:18:11 +00:00

Shell: Expand for loop's iterated expr before iterating over it

This only applies to the POSIX mode.
Fixes #21715.
This commit is contained in:
Ali Mohammad Pur 2023-11-17 21:28:55 +03:30 committed by Ali Mohammad Pur
parent b74f5b1ca1
commit 2eb0a8f3d2
2 changed files with 38 additions and 51 deletions

View file

@ -598,8 +598,17 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_reexpand(AST::ImmediateExpression& i
return nullptr;
}
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
return parse(value, m_is_interactive, false);
auto values = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_list(*this));
auto result = Vector<NonnullRefPtr<AST::Node>> {};
for (auto& value : values) {
if (auto node = parse(value, m_is_interactive, false))
result.append(node.release_nonnull());
}
if (values.size() == 1)
return result.take_first();
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(result));
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_of_variable(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)