diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-01-18 13:03:35 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-01-18 21:02:24 +0100 |
| commit | 132dcea0af0f14166783f0fd4b0df32bfb91f24a (patch) | |
| tree | 7ce03b31268188f9e858e74b3d2adfbe2b773709 /pkg | |
| parent | d2f8d5ab46fe67b2f03387be9e6f38ffe5f227ba (diff) | |
pkg/compiler: generate const[0] for flags w/o values
Generate const[0] for flags without values and for flags
with a single value which is 0.
This is the intention in all existing cases (e.g. an enum with types
of something, but there is really only 1 type exists).
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/compiler/types.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 2858f9fb2..8a488dca8 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -312,13 +312,6 @@ var typeFlags = &typeDesc{ name := args[0].Ident base.TypeName = name f := comp.intFlags[name] - if len(f.Values) == 0 { - // We can get this if all values are unsupported consts. - return &prog.IntType{ - IntTypeCommon: base, - Kind: prog.IntPlain, - } - } bitmask := true var combined uint64 values := genIntArray(f.Values) @@ -329,6 +322,16 @@ var typeFlags = &typeDesc{ } combined |= v } + if len(values) == 0 || len(values) == 1 && values[0] == 0 { + // We can get this if all values are unsupported consts. + // Also generate const[0] if we have only 1 flags value which is 0, + // this is the intention in all existing cases (e.g. an enum with types + // of something, but there is really only 1 type exists). + return &prog.ConstType{ + IntTypeCommon: base, + Val: 0, + } + } return &prog.FlagsType{ IntTypeCommon: base, Vals: values, |
