cast icon indicating copy to clipboard operation
cast copied to clipboard

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

Open ashep opened this issue 3 years ago • 0 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.

ashep avatar Aug 21 '21 15:08 ashep