From 8f99e65425004bfaff858b68654dd00cecbfb538 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 2 Feb 2025 05:48:51 -0300 Subject: [PATCH] v.parser: fix the error message position, for a `struct Abc`, that lacks a body (#23627) --- vlib/v/parser/struct.v | 2 +- vlib/v/parser/tests/struct_no_body_err.out | 5 +++++ vlib/v/parser/tests/struct_no_body_err.vv | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 vlib/v/parser/tests/struct_no_body_err.out create mode 100644 vlib/v/parser/tests/struct_no_body_err.vv diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 3c1d4b8037..abb368b0d3 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -65,7 +65,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl { mut pre_comments := p.eat_comments() no_body := p.tok.kind != .lcbr && p.tok.kind != .key_implements if language == .v && no_body { - p.error('`${p.tok.lit}` lacks body') + p.error_with_pos('`${p.tok.lit}` lacks body', name_pos) return ast.StructDecl{} } if name.len == 1 { diff --git a/vlib/v/parser/tests/struct_no_body_err.out b/vlib/v/parser/tests/struct_no_body_err.out new file mode 100644 index 0000000000..27e5852374 --- /dev/null +++ b/vlib/v/parser/tests/struct_no_body_err.out @@ -0,0 +1,5 @@ +vlib/v/parser/tests/struct_no_body_err.vv:1:8: error: `struct` lacks body + 1 | struct Lexer + | ~~~~~ + 2 | + 3 | struct Token { diff --git a/vlib/v/parser/tests/struct_no_body_err.vv b/vlib/v/parser/tests/struct_no_body_err.vv new file mode 100644 index 0000000000..2b5646bddc --- /dev/null +++ b/vlib/v/parser/tests/struct_no_body_err.vv @@ -0,0 +1,10 @@ +struct Lexer + +struct Token { + token_u string +} + +fn main() { + token := Token{"this is a token"} + println(token.token_u) +} \ No newline at end of file