From 2bd2d00caf9016d49dbaee2785569ce073f60288 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 4 May 2025 12:38:58 +0300 Subject: [PATCH] parser: fix panic for `struct Abc { pub mut: }` (fix #24404) (#24403) --- vlib/v/parser/struct.v | 4 +++- vlib/v/parser/tests/struct_with_empty_pub_mut_section.out | 0 vlib/v/parser/tests/struct_with_empty_pub_mut_section.vv | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 vlib/v/parser/tests/struct_with_empty_pub_mut_section.out create mode 100644 vlib/v/parser/tests/struct_with_empty_pub_mut_section.vv diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 21b2ba4c9..84f310a3e 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -213,7 +213,9 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl { mut option_pos := token.Pos{} if p.tok.kind == .rcbr { - ast_fields.last().next_comments << pre_field_comments + if ast_fields.len > 0 { + ast_fields.last().next_comments << pre_field_comments + } break } diff --git a/vlib/v/parser/tests/struct_with_empty_pub_mut_section.out b/vlib/v/parser/tests/struct_with_empty_pub_mut_section.out new file mode 100644 index 000000000..e69de29bb diff --git a/vlib/v/parser/tests/struct_with_empty_pub_mut_section.vv b/vlib/v/parser/tests/struct_with_empty_pub_mut_section.vv new file mode 100644 index 000000000..4e8415594 --- /dev/null +++ b/vlib/v/parser/tests/struct_with_empty_pub_mut_section.vv @@ -0,0 +1,2 @@ +pub struct Foo { +} -- 2.39.5