1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 23:12:08 +00:00

Shell: Immediately resolve value when setting a variable

The lazy resolution mechanism made it so that the variables were linked
together, causing unexpected behaviour:

    true
    x=$? # expected: x=0
    false
    echo $x # expected: 0, actual: 1
This commit is contained in:
Ali Mohammad Pur 2022-07-02 19:30:22 +04:30 committed by Ali Mohammad Pur
parent f94c7fc880
commit 6e24d845e0
2 changed files with 19 additions and 3 deletions

View file

@ -3414,6 +3414,7 @@ RefPtr<Value> VariableDeclarations::run(RefPtr<Shell> shell)
auto value = var.value->run(shell);
if (shell && shell->has_any_error())
break;
value = value->resolve_without_cast(shell);
shell->set_local_variable(name, value.release_nonnull());
}
@ -3703,6 +3704,14 @@ Vector<String> SpecialVariableValue::resolve_as_list(RefPtr<Shell> shell)
}
}
NonnullRefPtr<Value> SpecialVariableValue::resolve_without_cast(RefPtr<Shell> shell)
{
if (!shell)
return *this;
return make_ref_counted<ListValue>(resolve_as_list(shell));
}
TildeValue::~TildeValue()
{
}