Use HIL to limit concat to ast.TypeList
we can remove some type checks in the concat function
This commit is contained in:
parent
c15c0eb0cb
commit
c9e1522103
|
@ -311,31 +311,25 @@ func interpolationFuncCoalesce() ast.Function {
|
||||||
// multiple lists.
|
// multiple lists.
|
||||||
func interpolationFuncConcat() ast.Function {
|
func interpolationFuncConcat() ast.Function {
|
||||||
return ast.Function{
|
return ast.Function{
|
||||||
ArgTypes: []ast.Type{ast.TypeAny},
|
ArgTypes: []ast.Type{ast.TypeList},
|
||||||
ReturnType: ast.TypeList,
|
ReturnType: ast.TypeList,
|
||||||
Variadic: true,
|
Variadic: true,
|
||||||
VariadicType: ast.TypeAny,
|
VariadicType: ast.TypeList,
|
||||||
Callback: func(args []interface{}) (interface{}, error) {
|
Callback: func(args []interface{}) (interface{}, error) {
|
||||||
var outputList []ast.Variable
|
var outputList []ast.Variable
|
||||||
|
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
switch arg := arg.(type) {
|
for _, v := range arg.([]ast.Variable) {
|
||||||
case []ast.Variable:
|
switch v.Type {
|
||||||
for _, v := range arg {
|
case ast.TypeString:
|
||||||
switch v.Type {
|
outputList = append(outputList, v)
|
||||||
case ast.TypeString:
|
case ast.TypeList:
|
||||||
outputList = append(outputList, v)
|
outputList = append(outputList, v)
|
||||||
case ast.TypeList:
|
case ast.TypeMap:
|
||||||
outputList = append(outputList, v)
|
outputList = append(outputList, v)
|
||||||
case ast.TypeMap:
|
default:
|
||||||
outputList = append(outputList, v)
|
return nil, fmt.Errorf("concat() does not support lists of %s", v.Type.Printable())
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue