diff options
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/compiler/check.go | 12 | ||||
| -rw-r--r-- | pkg/compiler/testdata/errors2.txt | 6 |
2 files changed, 17 insertions, 1 deletions
diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 468b6e35e..022581771 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -248,7 +248,7 @@ func (comp *compiler) checkTypes() { func (comp *compiler) checkTypeValues() { for _, decl := range comp.desc.Nodes { - switch decl.(type) { + switch n := decl.(type) { case *ast.Call, *ast.Struct, *ast.Resource, *ast.TypeDef: comp.foreachType(decl, func(t *ast.Type, desc *typeDesc, args []*ast.Type, base prog.IntTypeCommon) { @@ -261,6 +261,16 @@ func (comp *compiler) checkTypeValues() { } } }) + case *ast.IntFlags: + allEqual := len(n.Values) >= 2 + for _, val := range n.Values { + if val.Value != n.Values[0].Value { + allEqual = false + } + } + if allEqual { + comp.error(n.Pos, "all %v values are equal %v", n.Name.Name, n.Values[0].Value) + } } } } diff --git a/pkg/compiler/testdata/errors2.txt b/pkg/compiler/testdata/errors2.txt index c862358cf..111db587f 100644 --- a/pkg/compiler/testdata/errors2.txt +++ b/pkg/compiler/testdata/errors2.txt @@ -370,6 +370,12 @@ foo$534(a ptr[in, flags[large_flags, int8]]) ### large_flags U16_MAX=0xffff does large_flags = U8_MAX, U16_MAX +equal_flags_0 = 0, 0, 0, 0 ### all equal_flags_0 values are equal 0 +equal_flags_1 = 42, 42, 42, 42 ### all equal_flags_1 values are equal 42 +non_equal_flags = 0, 0, 0, 1 + +equal_flags_call(a flags[equal_flags_0], b flags[equal_flags_1], c flags[non_equal_flags]) + type type500 proc[C1, 8, int8] ### values starting from 1 with step 8 overflow base type for 32 procs type type501 int8 ### unused type type501 type type502[C] const[C, int8] ### unused type type502 |
