From 53c6e46a51e0411b165f899c469a9ba45ec931ea Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 26 Oct 2022 14:33:58 +0800 Subject: [PATCH] parser: correct comptime path not found error position (fix #16189) (#16209) --- vlib/v/parser/comptime.v | 5 +++-- vlib/v/parser/tests/comptime_path_not_found_err.out | 6 ++++++ vlib/v/parser/tests/comptime_path_not_found_err.vv | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 vlib/v/parser/tests/comptime_path_not_found_err.out create mode 100644 vlib/v/parser/tests/comptime_path_not_found_err.vv diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 75019866f..f42badbad 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -106,6 +106,7 @@ fn (mut p Parser) comptime_call() ast.ComptimeCall { is_html := method_name == 'html' // $env('ENV_VAR_NAME') p.check(.lpar) + arg_pos := p.tok.pos() if method_name in ['env', 'pkgconfig', 'compile_error', 'compile_warn'] { s := p.tok.lit p.check(.string) @@ -213,9 +214,9 @@ fn (mut p Parser) comptime_call() ast.ComptimeCall { } } if is_html { - p.error('vweb HTML template "$path" not found') + p.error_with_pos('vweb HTML template "$tmpl_path" not found', arg_pos) } else { - p.error('template file "$path" not found') + p.error_with_pos('template file "$tmpl_path" not found', arg_pos) } return err_node } diff --git a/vlib/v/parser/tests/comptime_path_not_found_err.out b/vlib/v/parser/tests/comptime_path_not_found_err.out new file mode 100644 index 000000000..2181753cc --- /dev/null +++ b/vlib/v/parser/tests/comptime_path_not_found_err.out @@ -0,0 +1,6 @@ +vlib/v/parser/tests/comptime_path_not_found_err.vv:2:15: error: template file "tempate.txt" not found + 1 | fn main() { + 2 | tmp := $tmpl('tempate.txt') + | ~~~~~~~~~~~~~ + 3 | a := tmp + 4 | } diff --git a/vlib/v/parser/tests/comptime_path_not_found_err.vv b/vlib/v/parser/tests/comptime_path_not_found_err.vv new file mode 100644 index 000000000..25e42d891 --- /dev/null +++ b/vlib/v/parser/tests/comptime_path_not_found_err.vv @@ -0,0 +1,4 @@ +fn main() { + tmp := $tmpl('tempate.txt') + a := tmp +} -- 2.39.5