ast, fmt: fix formatting type decl with anon struct 2 (related #19356) (#19364)

This commit is contained in:
yuyi 2023-09-16 19:01:02 +08:00 committed by GitHub
parent 2e0a6ea4d4
commit 8fee351c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -1502,12 +1502,12 @@ pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
if node.is_pub { if node.is_pub {
f.write('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) sym := f.table.sym(node.parent_type)
if sym.info is ast.Struct { if sym.info is ast.Struct {
if sym.info.is_anon { if sym.info.is_anon {
f.write('type ${node.name} = ') 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.comments(node.comments, has_nl: false)
f.mark_types_import_as_used(node.parent_type) f.mark_types_import_as_used(node.parent_type)
return return

View File

@ -1,9 +1,9 @@
pub type Unit1 = struct {} pub type Unit1 = struct {}
pub type Unit2 = struct { pub type Unit2 = struct {
name string name string
age int age int
} }
pub const unit1 = Unit1{} pub const unit1 = Unit1{}