diff --git a/src/autoload.cpp b/src/autoload.cpp index 339c052ab..d096f5331 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -205,6 +205,14 @@ maybe_t autoload_t::resolve_command(const wcstring &cmd, const wcstrin } void autoload_t::perform_autoload(const wcstring &path, parser_t &parser) { + // We do the useful part of what exec_subshell does ourselves + // - we source the file. + // We don't create a buffer or check ifs or create a read_limit + wcstring script_source = L"source " + escape_string(path, ESCAPE_ALL); - exec_subshell(script_source, parser, false /* do not apply exit status */); + auto prev_statuses = parser.get_last_statuses(); + const cleanup_t put_back([&] { + parser.set_last_statuses(prev_statuses); + }); + parser.eval(script_source, io_chain_t{}); } diff --git a/tests/checks/syntax-error-location.fish b/tests/checks/syntax-error-location.fish index bf5c9a9ce..ca483f45c 100644 --- a/tests/checks/syntax-error-location.fish +++ b/tests/checks/syntax-error-location.fish @@ -32,3 +32,15 @@ $fish -c 'echo "unfinished "$(subshell' 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 +# CHECKERR: function error +# CHECKERR: ^ +# CHECKERR: from sourcing file ~/temp/error.fish +# CHECKERR: source: Error while reading file '{{.*}}/error.fish' +# CHECKERR: fish: Unknown command: error +# CHECKERR: fish: +# CHECKERR: set -g fish_function_path {{.*}}; error +# CHECKERR: ^