mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-28 12:45:13 +00:00
Computed variables are global
Variables like $status and $history showed up in all scopes, including universal, when querying with `set -q` or `set -S`. This makes it so they all only count as set in global scope, because we already only allow assignment to electric variables in global scope. Fixes #7032
This commit is contained in:
parent
46068cd257
commit
7cb452c7e7
2 changed files with 17 additions and 1 deletions
|
@ -734,7 +734,12 @@ maybe_t<env_var_t> env_scoped_impl_t::try_get_universal(const wcstring &key) con
|
||||||
maybe_t<env_var_t> env_scoped_impl_t::get(const wcstring &key, env_mode_flags_t mode) const {
|
maybe_t<env_var_t> env_scoped_impl_t::get(const wcstring &key, env_mode_flags_t mode) const {
|
||||||
const query_t query(mode);
|
const query_t query(mode);
|
||||||
|
|
||||||
maybe_t<env_var_t> result = try_get_computed(key);
|
maybe_t<env_var_t> result;
|
||||||
|
// Computed variables are effectively global and can't be shadowed.
|
||||||
|
if (query.global) {
|
||||||
|
result = try_get_computed(key);
|
||||||
|
}
|
||||||
|
|
||||||
if (!result && query.local) {
|
if (!result && query.local) {
|
||||||
result = try_get_local(key);
|
result = try_get_local(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -624,4 +624,15 @@ $FISH -c 'set __fish_test_universal_exported_var 2'
|
||||||
env | string match -e __fish_test_universal_exported_var
|
env | string match -e __fish_test_universal_exported_var
|
||||||
#CHECK: __fish_test_universal_exported_var=2
|
#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
|
true
|
||||||
|
|
Loading…
Reference in a new issue