Use HIL to limit concat to ast.TypeList

we can remove some type checks in the concat function
This commit is contained in:
James Bardin 2016-08-01 15:24:18 -04:00
parent c15c0eb0cb
commit c9e1522103
1 changed files with 12 additions and 18 deletions

View File

@ -311,31 +311,25 @@ func interpolationFuncCoalesce() ast.Function {
// multiple lists.
func interpolationFuncConcat() ast.Function {
return ast.Function{
ArgTypes: []ast.Type{ast.TypeAny},
ArgTypes: []ast.Type{ast.TypeList},
ReturnType: ast.TypeList,
Variadic: true,
VariadicType: ast.TypeAny,
VariadicType: ast.TypeList,
Callback: func(args []interface{}) (interface{}, error) {
var outputList []ast.Variable
for _, arg := range args {
switch arg := arg.(type) {
case []ast.Variable:
for _, v := range arg {
switch v.Type {
case ast.TypeString:
outputList = append(outputList, v)
case ast.TypeList:
outputList = append(outputList, v)
case ast.TypeMap:
outputList = append(outputList, v)
default:
return nil, fmt.Errorf("concat() does not support lists of %s", v.Type.Printable())
}
for _, v := range arg.([]ast.Variable) {
switch v.Type {
case ast.TypeString:
outputList = append(outputList, v)
case ast.TypeList:
outputList = append(outputList, v)
case ast.TypeMap:
outputList = append(outputList, v)
default:
return nil, fmt.Errorf("concat() does not support lists of %s", v.Type.Printable())
}
default:
return nil, fmt.Errorf("concat() does not support type %T", arg)
}
}