function: Error out for read-only variables

This will refuse to define the function instead of defining it with an
unusable argument.

Fixes #10842
This commit is contained in:
Fabian Boehm
2024-11-11 17:50:20 +01:00
parent 0ef811c86e
commit 960415db3f
2 changed files with 25 additions and 1 deletions

View File

@@ -162,6 +162,8 @@ end
rm -r $tmpdir
functions -e foo
function foo -p bar; end
# CHECKERR: {{.*}}function.fish (line {{\d+}}): function: bar: invalid process id
# CHECKERR: function foo -p bar; end
@@ -173,4 +175,16 @@ function foo --argument-names "banana pajama"; end
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
function foo --argument-names status; end
# CHECKERR: {{.*}}function.fish (line {{\d+}}): function: variable 'status' is read-only
# CHECKERR: function foo --argument-names status; end
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
echo status $status
# CHECK: status 2
functions -q foo
echo exists $status
# CHECK: exists 1
exit 0