From eaf92918e634472a36c2f91bac1bd8e98e18904b Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 11 Aug 2022 18:06:05 +0200 Subject: [PATCH] Fix error offset for `command (foo)` This used the decorated statement offset when the expansion errors refer to the command without decoration. --- src/parse_util.cpp | 5 ++++- tests/checks/expansion.fish | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 7943adb74..9f90aac65 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -1225,7 +1225,10 @@ static bool detect_errors_in_decorated_statement(const wcstring &buff_src, } if (parse_errors) { - parse_error_offset_source_start(&new_errors, source_start); + // The expansion errors here go from the *command* onwards, + // so we need to offset them by the *command* offset, + // excluding the decoration. + parse_error_offset_source_start(&new_errors, dst.command.source_range().start); vec_append(*parse_errors, std::move(new_errors)); } } diff --git a/tests/checks/expansion.fish b/tests/checks/expansion.fish index 15435161f..52bdfb957 100644 --- a/tests/checks/expansion.fish +++ b/tests/checks/expansion.fish @@ -324,8 +324,8 @@ $fish -c 'echo {}}' #CHECKERR: fish: Unexpected '}' for unopened brace expansion #CHECKERR: echo {}} #CHECKERR: ^ -$fish -c 'command (asd)' -#CHECKERR: fish: Command substitutions not allowed -#CHECKERR: command (asd) -#CHECKERR: ^ +printf '<%s>\n' ($fish -c 'command (asd)' 2>&1) +#CHECK: +#CHECK: +#CHECK: < ^~~~^> true