tpl/collections: Improve type handling in collections.Slice

Fixes #5188
This commit is contained in:
Bjørn Erik Pedersen
2018-09-09 10:15:11 +02:00
parent 7a97d3e6bc
commit fe6676c775
10 changed files with 275 additions and 68 deletions

View File

@@ -102,6 +102,23 @@ func convertNumber(v reflect.Value, to reflect.Kind) (reflect.Value, error) {
}
func newSliceElement(items interface{}) interface{} {
tp := reflect.TypeOf(items)
if tp == nil {
return nil
}
switch tp.Kind() {
case reflect.Array, reflect.Slice:
tp = tp.Elem()
if tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
return reflect.New(tp).Interface()
}
return nil
}
func isNumber(kind reflect.Kind) bool {
return isInt(kind) || isUint(kind) || isFloat(kind)
}