Forbid bad interactions

This commit is contained in:
Ian Wahbe 2021-11-06 20:25:54 -07:00
parent f8a98b2a86
commit 420f9546f0

View file

@ -2278,6 +2278,14 @@ func (t *types) bindProperties(path string, properties map[string]PropertySpec,
}
}
for name, prop := range propertyMap {
_, optional := prop.Type.(*OptionalType)
if many(!optional, prop.ConstValue != nil, prop.DefaultValue != nil) {
diags = diags.Append(errorf(path+name,
"Cannot specify more then one of 'required', 'const', or 'default'"))
}
}
sort.Slice(result, func(i, j int) bool {
return result[i].Name < result[j].Name
})
@ -2768,3 +2776,16 @@ func (fun *Function) NeedsOutputVersion() bool {
return true
}
// True if more then one boolean is true.
func many(booleans ...bool) bool {
var found bool
for _, b := range booleans {
if found && b {
return true
} else if b {
found = true
}
}
return false
}