From 662fb3f3d1f81a05af60a7dab02bdc29152099c4 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 26 Nov 2019 18:09:33 +0100 Subject: [PATCH] Fix line numbers in functions This added the function offset *again*, but it's already included in the line for the current file. And yes, I have explicitly tested a function file with a function defined at a later line. Fixes #6350 --- src/parser.cpp | 6 ------ tests/checks/line-number.fish | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 tests/checks/line-number.fish diff --git a/src/parser.cpp b/src/parser.cpp index 7e19cb065..aa437d004 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -484,12 +484,6 @@ int parser_t::get_lineno() const { int lineno = -1; if (execution_context) { lineno = execution_context->get_current_line_number(); - - // If we are executing a function, we have to add in its offset. - const wchar_t *function_name = is_function(); - if (function_name != nullptr) { - lineno += function_get_definition_lineno(function_name); - } } return lineno; } diff --git a/tests/checks/line-number.fish b/tests/checks/line-number.fish new file mode 100644 index 000000000..ea1a4f4ee --- /dev/null +++ b/tests/checks/line-number.fish @@ -0,0 +1,29 @@ +# RUN: %fish %s +# +# These lines left around because we need the line numbers. +# This file in general requires careful editing in the middle, I recommend appending. +function t --on-event linenumber + status line-number + status line-number + status line-number +end + +emit linenumber +# CHECK: 6 +# CHECK: 7 +# CHECK: 8 + +type --nonexistent-option-so-we-get-a-backtrace +# CHECKERR: type: Unknown option '--nonexistent-option-so-we-get-a-backtrace' +# CHECKERR: {{.*/type.fish}} (line 7): +# CHECKERR: argparse -n type -x t,p,P $options -- $argv +# CHECKERR: ^ +# CHECKERR: in function 'type' with arguments '--nonexistent-option-so-we-get-a-backtrace' +# CHECKERR: called on line 16 of file {{.*}}line-number.fish + +function line-number + status line-number +end + +line-number +# CHECK: 25