From 14cc59eef8374ac8013a05d5d14c4cd4af9d0979 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 6 Jan 2022 18:04:58 +0100 Subject: pkg/compiler: prohibit use of direction attribute on union fields Direction attributes on unions work in a confusing way and don't do what users may think they do. Now we have out_overlay attribute for structs that allows to have overlapping input and output fields. --- pkg/compiler/check.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'pkg/compiler/check.go') diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 676b96c5c..9f74f8a4b 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -184,7 +184,11 @@ func (comp *compiler) checkStructFields(n *ast.Struct, typ, name string) { } hasDirections, hasOutOverlay := false, false for fieldIdx, f := range n.Fields { - attrs := comp.parseAttrs(fieldAttrs, f, f.Attrs) + if n.IsUnion { + comp.parseAttrs(nil, f, f.Attrs) + continue + } + attrs := comp.parseAttrs(structFieldAttrs, f, f.Attrs) dirCount := attrs[attrIn] + attrs[attrOut] + attrs[attrInOut] if dirCount != 0 { hasDirections = true @@ -194,10 +198,6 @@ func (comp *compiler) checkStructFields(n *ast.Struct, typ, name string) { comp.error(f.Pos, "%v has multiple direction attributes", typ) } if attrs[attrOutOverlay] > 0 { - if n.IsUnion { - _, typ, name := f.Info() - comp.error(f.Pos, "unknown %v %v attribute %v", typ, name, attrOutOverlay.Name) - } if fieldIdx == 0 { comp.error(f.Pos, "%v attribute must not be specified on the first field", attrOutOverlay.Name) } @@ -325,7 +325,7 @@ func (comp *compiler) checkAttributeValues() { for _, f := range st.Fields { isOut := hasOutOverlay for _, attr := range f.Attrs { - desc := fieldAttrs[attr.Ident] + desc := structFieldAttrs[attr.Ident] if desc.CheckConsts != nil { desc.CheckConsts(comp, f, attr) } -- cgit mrf-deployment