diff --git a/src/env.cpp b/src/env.cpp index d7c526403..fd985c818 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -734,7 +734,12 @@ maybe_t env_scoped_impl_t::try_get_universal(const wcstring &key) con maybe_t env_scoped_impl_t::get(const wcstring &key, env_mode_flags_t mode) const { const query_t query(mode); - maybe_t result = try_get_computed(key); + maybe_t result; + // Computed variables are effectively global and can't be shadowed. + if (query.global) { + result = try_get_computed(key); + } + if (!result && query.local) { result = try_get_local(key); } diff --git a/tests/checks/set.fish b/tests/checks/set.fish index 89fc348b9..5c1096d1e 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -624,4 +624,15 @@ $FISH -c 'set __fish_test_universal_exported_var 2' env | string match -e __fish_test_universal_exported_var #CHECK: __fish_test_universal_exported_var=2 +# Test that computed variables are global. +# If they can be set they can only be set in global scope, +# so they should only be shown in global scope. +set -S status +#CHECK: $status: set in global scope, unexported, with 1 elements +#CHECK: $status[1]: |0| + +set -ql history +echo $status +#CHECK: 1 + true