From a960a3cde6f91dec1745dcf1123f47f7d7de3730 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 31 Mar 2022 16:14:59 -0700 Subject: [PATCH] Emit an error if time is used past the first command in a pipeline Fixes #8841 --- CHANGELOG.rst | 1 + src/parse_util.cpp | 8 ++++++++ tests/checks/syntax-error-location.fish | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b0237de3c..f593e1a9e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -36,6 +36,7 @@ Interactive improvements - Case-changing autosuggestions generated mid-token now correctly append only the suffix, instead of duplicating the token (:issue:`8820`). - ``ulimit`` learned a number of new options for the resource limits available on Linux, FreeBSD and NetBSD, and returns a specific warning if the limit specified is not available on the active operating system (:issue:`8823`). - The ``vared`` command can now successfully edit variables named "tmp" or "prompt" (:issue:`8836`). +- ``time`` now emits an error if used after the first command in a pipeline (:issue:`8841`). New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/parse_util.cpp b/src/parse_util.cpp index c74c20b8d..b42d4d2d3 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -39,6 +39,9 @@ /// Error message for arguments to 'end' #define END_ARG_ERR_MSG _(L"'end' does not take arguments. Did you forget a ';'?") +/// Error message when 'time' is in a pipeline. +#define TIME_IN_PIPELINE_ERR_MSG _(L"The 'time' command may only be at the beginning of a pipeline") + /// Maximum length of a variable name to show in error reports before truncation static constexpr int var_err_len = 16; @@ -1123,6 +1126,11 @@ static bool detect_errors_in_decorated_statement(const wcstring &buff_src, errored = append_syntax_error(parse_errors, source_start, INVALID_PIPELINE_CMD_ERR_MSG, command.c_str()); } + + // Similarly for time (#8841). + if (command == L"time") { + errored = append_syntax_error(parse_errors, source_start, TIME_IN_PIPELINE_ERR_MSG); + } } // $status specifically is invalid as a command, diff --git a/tests/checks/syntax-error-location.fish b/tests/checks/syntax-error-location.fish index ca483f45c..3f2aebfdc 100644 --- a/tests/checks/syntax-error-location.fish +++ b/tests/checks/syntax-error-location.fish @@ -11,6 +11,12 @@ $status # CHECK: # CHECK: < ^> +echo 'true | time false' | $fish 2>| string replace -r '(.*)' '<$1>' +# CHECK: +# CHECK: +# CHECK: < ^> + + echo ' (true one)