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