From 4b5b56452ba2dba15753a8b62ad8b987dbbc4e9c Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 3 Apr 2022 16:29:13 +0200 Subject: [PATCH] Make string syntax error location a bit more precise String tokens are subdivided by command substitutions. Some syntax errors can occur in the gap between two command substitutions. Make the caret point to the start of that gap, instead of the token start. --- src/parse_util.cpp | 2 +- tests/checks/syntax-error-location.fish | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 6cc381efb..10efed238 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -959,7 +959,7 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const ast::argumen wcstring unesc; if (!unescape_string(arg_src.c_str() + begin, end - begin, &unesc, UNESCAPE_SPECIAL)) { if (out_errors) { - append_syntax_error(out_errors, source_start, L"Invalid token '%ls'", + append_syntax_error(out_errors, source_start + begin, L"Invalid token '%ls'", arg_src.c_str()); } return 1; diff --git a/tests/checks/syntax-error-location.fish b/tests/checks/syntax-error-location.fish index 3f2aebfdc..52ef3a3a9 100644 --- a/tests/checks/syntax-error-location.fish +++ b/tests/checks/syntax-error-location.fish @@ -39,6 +39,11 @@ $fish -c 'echo "unfinished "$(subshell' 2>| string replace -r '.*' '<$0>' # CHECK: # CHECK: < ^> +$fish -c 'echo "ok $(echo still ok)syntax error: \x"' 2>| string replace -r '.*' '<$0>' +# CHECK: +# CHECK: +# CHECK: < ^> + echo "function error" >$TMPDIR/error.fish $fish -c "set -g fish_function_path $(string escape $TMPDIR); error" # CHECKERR: ~/temp/error.fish (line 1): Missing end to balance this function definition @@ -47,6 +52,6 @@ $fish -c "set -g fish_function_path $(string escape $TMPDIR); error" # CHECKERR: from sourcing file ~/temp/error.fish # CHECKERR: source: Error while reading file '{{.*}}/error.fish' # CHECKERR: fish: Unknown command: error -# CHECKERR: fish: +# CHECKERR: fish: # CHECKERR: set -g fish_function_path {{.*}}; error # CHECKERR: ^