diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index c87b1a5003..6c9fbeb58a 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -667,7 +667,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { } f.write(strings.repeat(` `, max - field.name.len - comments_len)) f.write(field_types[i]) - if field.attrs.len > 0 && field.attrs[0].name != 'ref_only' { // TODO a bug with [ref_only] attr being added to fields, fix it + if field.attrs.len > 0 { f.write(strings.repeat(` `, max_type - field_types[i].len)) f.inline_attrs(field.attrs) } diff --git a/vlib/v/fmt/tests/struct_no_extra_attr_keep.vv b/vlib/v/fmt/tests/struct_no_extra_attr_keep.vv new file mode 100644 index 0000000000..f1aab1d628 --- /dev/null +++ b/vlib/v/fmt/tests/struct_no_extra_attr_keep.vv @@ -0,0 +1,27 @@ +[typedef] +struct Foo { +} + +[typedef] +struct Bar { + x string + y int +} + +[ref_only] +struct Baz { + x string + y int +} + +[inline] +struct Spam { + x string + y int +} + +[deprecated] +struct Eggs { + y_y int [json: yY] + x string [deprecated] +} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 29e343452e..8b1acdaef2 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -12,6 +12,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { p.top_level_statement_start() // save attributes, they will be changed later in fields attrs := p.attrs + p.attrs = [] start_pos := p.tok.position() is_pub := p.tok.kind == .key_pub if is_pub {