1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

Shell: Make 'if' expressions return the unevaluated value of blocks

This makes it possible to actually put them in a sequence and cast them
to commands.
This commit is contained in:
AnotherTest 2021-01-18 10:06:13 +03:30 committed by Andreas Kling
parent 50473003be
commit 5ec139e728
3 changed files with 14 additions and 4 deletions

View file

@ -1690,12 +1690,18 @@ IfCond::IfCond(Position position, Optional<Position> else_position, NonnullRefPt
if (m_true_branch) {
auto true_branch = m_true_branch.release_nonnull();
m_true_branch = create<AST::Execute>(true_branch->position(), true_branch);
if (true_branch->is_execute())
m_true_branch = static_ptr_cast<AST::Execute>(true_branch)->command();
else
m_true_branch = move(true_branch);
}
if (m_false_branch) {
auto false_branch = m_false_branch.release_nonnull();
m_false_branch = create<AST::Execute>(false_branch->position(), false_branch);
if (false_branch->is_execute())
m_false_branch = static_ptr_cast<AST::Execute>(false_branch)->command();
else
m_false_branch = move(false_branch);
}
}