Skip to content

Commit

Permalink
fmt: keep anon struct decl fields in interfaces (#19461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 authored Sep 28, 2023
1 parent 4941a47 commit 9a03e18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion vlib/v/fmt/fmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/fmt/tests/interface_anon_struct_decl_keep.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Foo {
field struct {
bar int
}
}

0 comments on commit 9a03e18

Please sign in to comment.