ast: support attributes for `ast.SumType` (#13010)
parent
4d166e3b55
commit
9cbfa882e6
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 ')
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue