Skip to content

Commit 2bd2d00

Browse files
authored
parser: fix panic for struct Abc { pub mut: } (fix #24404) (#24403)
1 parent cf36360 commit 2bd2d00

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

vlib/v/parser/struct.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
213213
mut option_pos := token.Pos{}
214214

215215
if p.tok.kind == .rcbr {
216-
ast_fields.last().next_comments << pre_field_comments
216+
if ast_fields.len > 0 {
217+
ast_fields.last().next_comments << pre_field_comments
218+
}
217219
break
218220
}
219221

vlib/v/parser/tests/struct_with_empty_pub_mut_section.out

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub struct Foo {
2+
}

0 commit comments

Comments
 (0)