From 5ef8dbdf5a63ccf7e069527dbb2493dc2ef0c319 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 2 Mar 2018 15:44:54 +0100 Subject: pkg/compiler: support size attribute for unions --- pkg/compiler/check.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'pkg/compiler/check.go') diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 2a6afae3a..4dac37260 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -240,10 +240,11 @@ func (comp *compiler) checkAttributeValues() { switch n := decl.(type) { case *ast.Struct: for _, attr := range n.Attrs { - if !n.IsUnion && attr.Ident == "size" { + if attr.Ident == "size" { + _, typ, name := n.Info() if comp.structIsVarlen(n.Name.Name) { - comp.error(attr.Pos, "varlen struct %v has size attribute", - n.Name.Name) + comp.error(attr.Pos, "varlen %v %v has size attribute", + typ, name) } sz := attr.Args[0].Value if sz == 0 || sz > 1<<20 { @@ -906,7 +907,7 @@ func (comp *compiler) checkVarlen(n *ast.Struct) { // Non-varlen unions can't have varlen fields. // Non-packed structs can't have varlen fields in the middle. if n.IsUnion { - if varlen := comp.parseUnionAttrs(n); varlen { + if varlen, _ := comp.parseUnionAttrs(n); varlen { return } } else { -- cgit mrf-deployment