diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2022-01-06 18:04:58 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2022-01-11 16:30:08 +0100 |
| commit | 14cc59eef8374ac8013a05d5d14c4cd4af9d0979 (patch) | |
| tree | 558db1b673e2b96ddefd7cb4776b7d6fe28ca9ec /pkg/compiler/check.go | |
| parent | 1a2fb60b1e34cbc7f21351da8f9e3e253173bde8 (diff) | |
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.
Diffstat (limited to 'pkg/compiler/check.go')
| -rw-r--r-- | pkg/compiler/check.go | 12 |
1 files changed, 6 insertions, 6 deletions
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) } |
