From 8fee351c5b0d1f21d49229fbf65ddb2e3bd18b9e Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 16 Sep 2023 19:01:02 +0800 Subject: [PATCH] ast, fmt: fix formatting type decl with anon struct 2 (related #19356) (#19364) --- vlib/v/fmt/fmt.v | 4 ++-- vlib/v/fmt/tests/type_decl_with_anon_struct_keep.vv | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 549e006a7d..c4c7b30e73 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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 diff --git a/vlib/v/fmt/tests/type_decl_with_anon_struct_keep.vv b/vlib/v/fmt/tests/type_decl_with_anon_struct_keep.vv index f77285bb16..14dc06c5f1 100644 --- a/vlib/v/fmt/tests/type_decl_with_anon_struct_keep.vv +++ b/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{}