Skip to content

Commit

Permalink
ast, fmt: fix formatting type decl with anon struct 2 (related #19356) (
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Sep 16, 2023
1 parent 2e0a6ea commit 8fee351
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions vlib/v/fmt/fmt.v
Expand Up @@ -1502,12 +1502,12 @@ pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
if node.is_pub {
f.write('pub ')
}
// aliases of anon struct: `type foo = struct {}`
// aliases of anon struct: `type Foo = struct {}`
sym := f.table.sym(node.parent_type)
if sym.info is ast.Struct {
if sym.info.is_anon {
f.write('type ${node.name} = ')
f.write_anon_struct_field_decl(node.parent_type, ast.StructDecl{ fields: sym.info.fields })
f.struct_decl(ast.StructDecl{ fields: sym.info.fields }, true)
f.comments(node.comments, has_nl: false)
f.mark_types_import_as_used(node.parent_type)
return
Expand Down
6 changes: 3 additions & 3 deletions vlib/v/fmt/tests/type_decl_with_anon_struct_keep.vv
@@ -1,9 +1,9 @@
pub type Unit1 = struct {}

pub type Unit2 = struct {
name string
age int
}
name string
age int
}

pub const unit1 = Unit1{}

Expand Down

0 comments on commit 8fee351

Please sign in to comment.