Array is typed to whatever the first element is. If there is not first element, the array element type is invalid.
(source RegoSource, nodes ...Node)
| 16 | // Array is typed to whatever the first element is. If there is not first |
| 17 | // element, the array element type is invalid. |
| 18 | func Array(source RegoSource, nodes ...Node) (Node, error) { |
| 19 | for i := 1; i < len(nodes); i++ { |
| 20 | if reflect.TypeOf(nodes[0]) != reflect.TypeOf(nodes[i]) { |
| 21 | // Do not allow mixed types in arrays |
| 22 | return nil, xerrors.Errorf("array element %d in %q: type mismatch", i, source) |
| 23 | } |
| 24 | } |
| 25 | return ASTArray{Value: nodes, Source: source}, nil |
| 26 | } |
| 27 | |
| 28 | func (ASTArray) UseAs() Node { return ASTArray{} } |
| 29 |