spf13 / cast

safe and easy casting from one type to another in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ToIntSlice() and ToStringSlice(nil) behave differently for nil values

ashep opened this issue · comments

https://play.golang.org/p/5kUZwo1uV9W

package main

import (
	"fmt"
	"github.com/spf13/cast"
)

func main() {
	fmt.Printf("%#v\n", cast.ToIntSlice(nil))
	fmt.Printf("%#v\n", cast.ToStringSlice(nil))
}

Output:

[]int{}
[]string(nil)

In first line an empty slice returned, while second line returns a nil slice.