Allow overwriting argv with function -a and -V

Previously, if you called a function parameter 'argv', within the body
of the function, argv would be set to *all* the arguments to the
function, and not the one indicated by the parameter name.
The same behaviour happened if you inherited a variable named 'argv'.
Both behaviours were quite surprising, so this commit makes things more
obvious, although they could alternatively simply be made errors.

Part of #11780
This commit is contained in:
Isaac Oscar Gariano
2025-08-22 18:46:56 +10:00
committed by Johannes Altmanninger
parent 7a07c08860
commit 93c4d63295
3 changed files with 33 additions and 2 deletions

View File

@@ -192,4 +192,26 @@ end
# CHECKERR: function ()
# CHECKERR: ^
# Tests the --argument-names and --inherit-variable can overwrite argv
function t --argument-names a argv c
echo $argv
end
t 1 2 3
#CHECK: 2
function t -a argv
echo $argv
end
t 1 2 3
#CHECK: 1
function outer
function inner -v argv -V argv
echo $argv
end
set -gx argv 4 5 6
end
outer 1 2 3
#CHECK: 1 2 3
exit 0