ast: support attributes for `ast.SumType` (#13010)

pull/13097/head
Ken 2022-01-08 23:35:10 +09:00 committed by GitHub
parent 4d166e3b55
commit 9cbfa882e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 0 deletions

View File

@ -1092,6 +1092,7 @@ pub:
comments []Comment comments []Comment
typ Type typ Type
generic_types []Type generic_types []Type
attrs []Attr // attributes of type declaration
pub mut: pub mut:
variants []TypeNode variants []TypeNode
} }

View File

@ -1293,6 +1293,7 @@ pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) {
} }
pub fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl) { pub fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl) {
f.attrs(node.attrs)
start_pos := f.out.len start_pos := f.out.len
if node.is_pub { if node.is_pub {
f.write('pub ') f.write('pub ')

View File

@ -0,0 +1,14 @@
[derive: 'DeserBincode,SerBincode']
type OneOf = ItemA | ItemB
[derive: 'DeserBincode,SerBincode']
struct ItemA {
a string
}
[derive: 'DeserBincode,SerBincode']
struct ItemB {
b int
bb u64
bbb string
}

View File

@ -3465,6 +3465,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
is_pub: is_pub is_pub: is_pub
variants: sum_variants variants: sum_variants
generic_types: generic_types generic_types: generic_types
attrs: p.attrs
pos: decl_pos pos: decl_pos
comments: comments comments: comments
} }