From 367da548ff2edf7ccd749c86e6fdfba0e5af7a05 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 20 Apr 2023 20:14:30 +0330 Subject: [PATCH] Shell: Make null_or_alternative actually look up the given variable --- Userland/Shell/ImmediateFunctions.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Shell/ImmediateFunctions.cpp b/Userland/Shell/ImmediateFunctions.cpp index f819f91483..5be2d7a8a0 100644 --- a/Userland/Shell/ImmediateFunctions.cpp +++ b/Userland/Shell/ImmediateFunctions.cpp @@ -515,9 +515,14 @@ ErrorOr> Shell::immediate_null_or_alternative(AST::ImmediateEx return nullptr; } - auto value = TRY(TRY(const_cast(*arguments.first()).run(*this))->resolve_without_cast(*this)); + auto name = TRY(TRY(const_cast(*arguments.first()).run(*this))->resolve_as_string(*this)); + auto frame = find_frame_containing_local_variable(name); + if (!frame) + return make_ref_counted(invoking_node.position(), ""_short_string, AST::StringLiteral::EnclosureType::None); + + auto value = frame->local_variables.get(name.bytes_as_string_view()).value(); if ((value->is_string() && TRY(value->resolve_as_string(*this)).is_empty()) || (value->is_list() && TRY(value->resolve_as_list(*this)).is_empty())) - return make_ref_counted(invoking_node.position(), value); + return make_ref_counted(invoking_node.position(), *value); return arguments.last(); }