From 9a03e18b8165b783e80336a0e81978a927820c55 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Thu, 28 Sep 2023 21:29:45 +0530 Subject: [PATCH] fmt: keep anon struct decl fields in interfaces (#19461) --- vlib/v/fmt/fmt.v | 12 +++++++++++- vlib/v/fmt/tests/interface_anon_struct_decl_keep.vv | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/interface_anon_struct_decl_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 7b9b960001a422..110ba101f85d4f 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1380,7 +1380,17 @@ pub fn (mut f Fmt) interface_field(field ast.StructField) { if before_comments.len > 0 { f.comments(before_comments, level: .indent) } - f.write('\t${field.name} ${ft}') + sym := f.table.sym(field.typ) + if sym.info is ast.Struct { + if sym.info.is_anon { + f.write('\t${field.name} ') + f.write_anon_struct_field_decl(field.typ, ast.StructDecl{ fields: sym.info.fields }) + } else { + f.write('\t${field.name} ${ft}') + } + } else { + f.write('\t${field.name} ${ft}') + } if end_comments.len > 0 { f.comments(end_comments, level: .indent) } else { diff --git a/vlib/v/fmt/tests/interface_anon_struct_decl_keep.vv b/vlib/v/fmt/tests/interface_anon_struct_decl_keep.vv new file mode 100644 index 00000000000000..ba784fdc85b1fe --- /dev/null +++ b/vlib/v/fmt/tests/interface_anon_struct_decl_keep.vv @@ -0,0 +1,5 @@ +interface Foo { + field struct { + bar int + } +}