parser: fix duplicated struct attrs on first field (#6859)
parent
4415feb2df
commit
ee5ad2a653
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue