From b24377d3b804fcff672958be094c64d43aba3484 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 25 Mar 2026 23:53:43 +0300 Subject: [PATCH] parser: fix incorrect error message for badly constructed struct (fixes #25380) --- vlib/v/parser/struct.v | 3 +++ .../parser/tests/struct_missing_mut_section_colon_err.out | 7 +++++++ .../parser/tests/struct_missing_mut_section_colon_err.vv | 8 ++++++++ 3 files changed, 18 insertions(+) create mode 100644 vlib/v/parser/tests/struct_missing_mut_section_colon_err.out create mode 100644 vlib/v/parser/tests/struct_missing_mut_section_colon_err.vv diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 37737528d..510a6e69b 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -195,6 +195,9 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl { is_field_pub = false is_field_mut = true is_field_global = false + } else if p.tok.kind == .key_mut { + p.error_with_pos('missing `:` after `mut` in struct', p.tok.pos()) + return ast.StructDecl{} } else if p.tok.kind == .key_global && p.peek_tok.kind == .colon { if global_pos != -1 { p.error('redefinition of `global` section') diff --git a/vlib/v/parser/tests/struct_missing_mut_section_colon_err.out b/vlib/v/parser/tests/struct_missing_mut_section_colon_err.out new file mode 100644 index 000000000..c97457f87 --- /dev/null +++ b/vlib/v/parser/tests/struct_missing_mut_section_colon_err.out @@ -0,0 +1,7 @@ +vlib/v/parser/tests/struct_missing_mut_section_colon_err.vv:5:2: error: missing `:` after `mut` in struct + 3 | + 4 | struct Bar { + 5 | mut foos []Foo + | ~~~ + 6 | } + 7 | diff --git a/vlib/v/parser/tests/struct_missing_mut_section_colon_err.vv b/vlib/v/parser/tests/struct_missing_mut_section_colon_err.vv new file mode 100644 index 000000000..45377a9b7 --- /dev/null +++ b/vlib/v/parser/tests/struct_missing_mut_section_colon_err.vv @@ -0,0 +1,8 @@ +struct Foo { +} + +struct Bar { + mut foos []Foo +} + +fn main() {} -- 2.39.5