From 172601299f6cfa1b03b8ce053b25e0509b87e51c Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Mon, 11 Oct 2021 00:27:44 -0700 Subject: [PATCH] builtin _ is now a reserved keyword Similar to `test`, `_` is so likely to at least slow down if not break all things catastrophically that it ought not be allowed as a function name. Fixes #8342 --- CHANGELOG.rst | 3 ++- src/parser_keywords.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e13d8493a..9095b862c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -45,7 +45,8 @@ Scripting improvements - ``return`` can now be used outside of functions. In scripts it does the same thing as :ref:`exit `, in the commandline it sets ``$status`` without exiting (:issue:`8148`). - An oversight prevented all syntax checks from running on commands given to ``fish -c`` (:issue:`8171`). This includes checks like e.g. ``exec`` not being allowed in a pipeline and ``$$`` not being a valid variable. Most of these would have triggered an assert or other error before. - ``fish_indent`` now correctly reformats tokens that end with a backslash followed by a newline (:issue:`8197`). -- ``set`` learned a new option ``--function`` to set a variable in the function's top scope. This should be a more familiar way of scoping variables and avoids issues with ``--local``, which is actually block-scoped. (:issue:`565`, :issue:`8145`):: +- ``set`` learned a new option ``--function`` to set a variable in the function's top scope. This should be a more familiar way of scoping variables and avoids issues with ``--local``, which is actually block-scoped (:issue:`565`, :issue:`8145`). +- ``_`` is now a reserved keyword (:isues:`8342`).:: function demonstration if true diff --git a/src/parser_keywords.cpp b/src/parser_keywords.cpp index ad720c344..a26d217ce 100644 --- a/src/parser_keywords.cpp +++ b/src/parser_keywords.cpp @@ -24,7 +24,7 @@ static const string_set_t block_keywords = {L"for", L"while", L"if", 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"["}; + L"read", L"string", L"set", L"status", L"test", L"[", 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