Skip to content

Commit

Permalink
parser: fix formatting struct decl with comments (#20207)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Dec 18, 2023
1 parent 050344a commit a8e0ced
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions vlib/v/fmt/tests/struct_decl_with_comments_expected.vv
@@ -0,0 +1,3 @@
struct ABC { // size: 0x1=1 (source) (123 45 67) 20B
ff [0x20]u8
}
4 changes: 4 additions & 0 deletions vlib/v/fmt/tests/struct_decl_with_comments_input.vv
@@ -0,0 +1,4 @@
struct ABC //size: 0x1=1 (source) (123 45 67) 20B
{
ff[0x20] u8
}
4 changes: 2 additions & 2 deletions vlib/v/parser/struct.v
Expand Up @@ -52,6 +52,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
p.table.reset_parsing_type()
}
generic_types, _ := p.parse_generic_types()
mut pre_comments := p.eat_comments()
no_body := p.tok.kind != .lcbr
if language == .v && no_body {
p.error('`${p.tok.lit}` lacks body')
Expand Down Expand Up @@ -93,11 +94,10 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
mut is_field_pub := false
mut is_field_global := false
mut last_line := p.prev_tok.pos().line_nr + 1
mut pre_comments := []ast.Comment{}
mut end_comments := []ast.Comment{}
if !no_body {
p.check(.lcbr)
pre_comments = p.eat_comments()
pre_comments << p.eat_comments()
mut i := 0
for p.tok.kind != .rcbr {
mut comments := []ast.Comment{}
Expand Down

0 comments on commit a8e0ced

Please sign in to comment.