v.parser: fix the error message position, for a struct Abc, that lacks a body (#23627)

This commit is contained in:
Felipe Pena 2025-02-02 05:48:51 -03:00 committed by GitHub
parent e68fab82c4
commit 8f99e65425
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -0,0 +1,10 @@
struct Lexer
struct Token {
token_u string
}
fn main() {
token := Token{"this is a token"}
println(token.token_u)
}