parser: fix duplicated struct attrs on first field (#6859)

pull/6866/head
Lukas Neubert 2020-11-17 21:25:54 +01:00 committed by GitHub
parent 4415feb2df
commit ee5ad2a653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -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)
}

View File

@ -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]
}

View File

@ -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 {