aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/check.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-13 13:49:27 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-13 14:27:16 +0100
commit857a060fe3a415c1909ad8a342d9ca21019ab2fc (patch)
treee3dbcf413b8fe04b79b7f1f36962ec2733d7f704 /pkg/compiler/check.go
parente32b6fa920e7300d16c190c1138dd042a9df7ea2 (diff)
pkg/compiler: check for flags with all equal values
There is no point in having flags when values are equal. This can only mean a typo or other bug. Check for such cases and fix 3 existing precedents.
Diffstat (limited to 'pkg/compiler/check.go')
-rw-r--r--pkg/compiler/check.go12
1 files changed, 11 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)
+ }
}
}
}