rapid
rapid copied to clipboard
Make sure we return nil slices as empty slices sometimes
As there is code that can work with a := []int{}
, but fail with var a []int
.
Can we treat empty slices as having something like len = -1
during generation?
The only time I can think of where go will handle those differently is in comparison to nil. For example, the following will only print "a is nil" once:
var a []int
if a == nil {
fmt.Println("a is nil") // this will print
}
a = []int{}
if a == nil {
fmt.Println("a is nil") // this won't
}
Closing as it looks like there is not a lot of value in this.