1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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
typ Type
generic_types []Type
attrs []Attr // attributes of type declaration
pub mut:
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) {
f.attrs(node.attrs)
start_pos := f.out.len
if node.is_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
variants: sum_variants
generic_types: generic_types
attrs: p.attrs
pos: decl_pos
comments: comments
}