Add string to reserved keywords

Since `string match` now creates variables, wrapping `string`
necessarily breaks things, so we need to disallow it.

See #7459, #7509.
This commit is contained in:
Fabian Homborg 2020-12-06 15:31:04 +01:00
parent 9140fc7931
commit aa895645dd
2 changed files with 11 additions and 3 deletions

View file

@ -22,9 +22,9 @@ static const wcstring subcommand_keywords[]{L"command", L"builtin", L"while", L"
static const string_set_t block_keywords = {L"for", L"while", L"if",
L"function", L"switch", L"begin"};
static const wcstring reserved_keywords[] = {L"end", L"case", L"else", L"return",
L"continue", L"break", L"argparse", L"read",
L"set", L"status", L"test", L"["};
static const wcstring reserved_keywords[] = {
L"end", L"case", L"else", L"return", L"continue", L"break", L"argparse",
L"read", L"string", L"set", L"status", L"test", L"["};
// The lists above are purposely implemented separately from the logic below, so that future
// maintainers may assume the contents of the list based off their names, and not off what the

View file

@ -681,3 +681,11 @@ echo $status
yes | string replace -q y n
echo $status
# CHECK: 0
# `string` can't be wrapped properly anymore, since `string match` creates variables:
function string
builtin string $argv
end
# CHECKERR: checks/string.fish (line {{\d+}}): function: The name 'string' is reserved, and cannot be used as a function name
# CHECKERR: function string
# CHECKERR: ^